﻿// JScript File
$(document).ready(function () {
    $(".mouseOver").hover(function () {
        $(this).attr("src", $(this).attr("src").split(".").join("-ovr."));
    }, function () {
        $(this).attr("src", $(this).attr("src").split("-ovr.").join("."));
    });

	
		
	
    slideBannerText();

    initKickOuts(3);

    $('.cbGalImage').colorbox();

    $tabs = $("#tabs").tabs();

    if ($.query.get("t") == "p") {
        $tabs = $tabs.tabs('select', 1);
    } else {
        $tabs = $tabs.tabs('select', 0);
    }

    prepGallery(); //prepare onload
    $('#tabs ul li a').click(function () {
        prepGallery(); //prepare again when a new tab becomes visible
    });

    //Floorplans Page
    $("a[rel='gallery']").colorbox({ onComplete: function () {
        $('#cboxLoadedContent').css('padding-top', '30px');
        $('#cboxTitle').hide();
        $('#cboxNext').hide();
        $('#cboxPrevious').hide();
        $('#cboxSlideshow').hide();
        $('#cboxCurrent').hide();
    }
    });
});

function slideBannerText() {
    setTimeout(function () { $('.slider').animate({ left: '-=428' }, 7000); }, 500);
}

function loadHomeBanner() {
    //var vidFiles = new Array('flv/RWS_30_Mortgage_Vimeo.flv', 'flv/kingsbury.flv', 'flv/Construction_700.flv');
    //verlicon(vidIndex);

 var key 
    
    if (window.location.toString().indexOf('shuster') > -1 ) {

        key = '#@b0096bab9ed590833de';

    } else {

        key = '#@01fd934047cd9d6e0a0';

    }
    
    flowplayer("videoBox", "http://builds.flowplayer.netdna-cdn.com/60176/70036/flowplayer.commercial-3.2.7-0.swf", {
        key: key,
        play: { opacity: 0 },
        playlist: [
			{ url:'http://rwscustomhomes.com/swf/flv/RWS_30_Mortgage_Vimeo.mp4', autoPlay: true, scaling: 'orig', onFinish: function () { changeClip(1); } },
            { url: '/uploads/bannerMedia/top10.jpg', scaling: 'orig', autoPlay: true},
            { url:'http://rwscustomhomes.com/swf/flv/Top10.mp4', bufferLength: 3, autoPlay: false, autoBuffering:true, scaling: 'orig', onFinish: function () { changeClip(2); } },
            { url: '/uploads/bannerMedia/construction.jpg', scaling: 'orig', autoPlay: true},
            { url:'http://rwscustomhomes.com/swf/flv/Construction.mp4', bufferLength: 3, autoPlay: false, autoBuffering:true, scaling: 'orig', onFinish: function () { changeClip(0);} },
            { url: '/uploads/bannerMedia/ma_poster.jpg', scaling: 'orig', autoPlay: true }
        ],
        plugins: {
            controls: {
                url: 'http://releases.flowplayer.org/flowplayer.controls/flowplayer.controls-3.2.5.swf',
                opacity: 0
            }
        }
    });
}

function changeClip(_index) {
    var menuItems = $('.menuItem');
    $(menuItems).removeClass('miActive');
    $(menuItems[_index]).addClass('miActive');
}

function prepGallery() {
    $('.galRow').each(function () {
        var _this = $(this);
        var isOver = false;
        var img = $(_this).children('.galImage').children('a').children('img').each(function () {
            var thisHeight = $(this).height();

            if (thisHeight > 81) {
                isOver = true;
                return;
            } else {
                //isOver = false;
            }
        });

        //verlicon(isOver);
        //if (isOver == true) {
        var tallestHeight = 0;

        $(_this).children('.galImage').children('a').children('img').each(function () {
            var thisImg = $(this);
            var imgHeight = $(thisImg).height();
            if (imgHeight > tallestHeight) {
                tallestHeight = imgHeight;
            }

            if (imgHeight <= 121) {
                var diff = 121 - imgHeight;
                //$(thisImg).parent().parent().css('padding-top', diff);
            }
        });

        var thisPadding;
        $(_this).children('.galImage').children('a').children('img').each(function () {
            var thisImg = $(this);
            var imgHeight = $(thisImg).height();
            if (imgHeight <= 121) {
                var diff = tallestHeight - imgHeight;
                $(thisImg).parent().parent().css('padding-top', diff);
            }
        });


        //}
    });

    $('.galImage a').children('img').each(function () {
        var __this = $(this);
        var imgWidth = $(__this).width();
        //verlicon(imgWidth < 121);
        if (imgWidth <= 121) {
            var diff = 121 - imgWidth;
            $(__this).parent().siblings('.smOverlay').css('padding-left', diff / 2);
            $(__this).parent().siblings('p').css('padding-left', diff / 2);
            $(__this).parent().siblings('p').css('padding-right', diff / 2);
        } else {
            $(__this).parent().siblings('p').css('padding-left', '0');
            $(__this).parent().siblings('p').css('padding-right', '0');
        }
    });
}

function Validate(controlName) {
    var ddl = document.getElementById(controlName);
    if (ddl.selectedIndex == 0)
        return false;
    return true;
}

function loadFMS(fmsURL, vidTitle) {
    $.colorbox({ width: "700px", height: "650px", iframe: true, href: fmsURL, open: true, title: vidTitle });
}

function loadSWF(videoURL, flvWidth, flvHeight, vidTitle, desc) {
    //alert(flvWidth);

    var flashvars = {
        //rtmpStream: videoURL,loadSWF
        isFMS: "false",
        btnPlayPause_x: 13,
        btnPlayPause_y: 7,
        flvFile: videoURL
    };
    var params = {
        wmode: "opaque",
        base: "swf/",
        scale: "noscale"
    };
    var attributes = {
    };

    var cbWidth = parseInt(flvWidth) + 100;
    var cbHeight = parseInt(flvHeight) + 190 + 40;

    flvHeight = parseInt(flvHeight) + 40;

    $("#flvPlayer").css("width", flvWidth + "px");
    $("#flvPlayer").css("height", flvHeight + "px");
    $("#flvPlayer").css("padding-left", parseInt(((cbWidth - flvWidth) / 3.4)) + "px");
    $.colorbox({ width: cbWidth + "px", height: cbHeight + "px", inline: true, name: desc, href: "#flvPlayer", open: true, title: "<strong>Now Playing: </strong>" + vidTitle });
    swfobject.embedSWF("/swf/fmsPlayer.swf", "flashPlayer", flvWidth, flvHeight, "9.0.155", "", flashvars, params, attributes);
}

function initFlowPlayer(videoURL, flvWidth, flvHeight, vidTitle, desc) {
    var cbWidth = parseInt(flvWidth) + 100;
    var cbHeight = parseInt(flvHeight) + 190;

    flvHeight = parseInt(flvHeight);

    $("#flvPlayer").css("width", flvWidth + "px");
    $("#flvPlayer").css("height", flvHeight + "px");
    $("#flvPlayer").css("padding-left", parseInt(((cbWidth - flvWidth) / 3.4)) + "px");
    $.colorbox({ width: cbWidth + "px", height: cbHeight + "px", inline: true, name: desc, href: "#flvPlayer", open: true, title: "<strong>Now Playing: </strong>" + vidTitle });

    loadFlowPlayer(videoURL);
}

function loadFlowPlayer(_video) {
    flowplayer("flashPlayer", "http://builds.flowplayer.netdna-cdn.com/60176/70036/flowplayer.commercial-3.2.7-0.swf", {
        key: '#@01fd934047cd9d6e0a0',
        play: { opacity: 0 },
        clip: {
            url: 'http://rwscustomhomes.com/swf/' + _video,
            autoplay: true,
            scaling: 'orig'
        }
    });
}

function confirmDel(ID) {
    if (window.confirm("Are you SURE you want to delete this item?")) {
        var w = window.location.toString();
        w = w.replace(/\?.*/, "");
        window.location = w + "?del=" + ID;
    }
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function verlicon(data) {
    if (window.console && window.console.firebug) {
        //Firebug is enabled
        console.log(data);
    } else if (window.console) {
        console.log(data);
    }
}
