function PopupWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin", "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupNamedWindow(aName, aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, aName, "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupUniqueWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin" + (new Date()).getTime(), "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}


function Roll(img_name, img_src)
{
   document.getElementById(img_name).src = img_src;}

function HideControl()
{
	var ctrl;
	
	for (i=0; i<arguments.length; i++)
	{
		ctrl = document.getElementById(arguments[i]);
		if (ctrl.style.display != "none")
		{
			ctrl.style.display = "none";
		}
	}
}

function ShowControl()
{
	var ctrl;
	
	for (i=0; i<arguments.length; i++)
	{
		ctrl = document.getElementById(arguments[i]);
		
		if (ctrl.style.display == "none")
		{
			ctrl.style.display = "";
		}
	}
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function doPopUpImage(id) {
    var url = ("PopupImage.aspx?id=" + id);
    PopupWindow(url, 630, 600, '', '', '', '', '', '');
}

$(document).ready(initJQuery);

function initJQuery() {

    $(".validate").click(function() {
        $.validity.start();
        $(".requiredfield").require();
        $(".datefield").match("date");
        $(".emailfield").match("email");
        $(".integerfield").match("number");
        $(".numberfield").match("number");
        $(".numericfield").match("number");
        $(".decimalfield").match("number");
        $(".moneyfield").match("number");
        var result = $.validity.end();
        if (!result.valid) {
            $(".validity-summary-container").show();
        }
        return result.valid;
    });
    
    $('.marquee-cycle').cycle({ fx: 'fade', speed: 1500, timeout: 5000 });
    
    $('.gallery-cycle').cycle({
        fx: 'fade',
        speed: 1500,
        timeout: 5000,
        pager: '.details-gallery-thumbs',
        pagerAnchorBuilder: function(index, element) {
            return '.details-gallery-thumbs div:eq(' + index + ') a';
        }
    });

    $('.tabs').tabs();
    
    try {
        $(".datefield").datepicker({ changeMonth: true, changeYear: true, numberOfMonths: 1, showOtherMonths: true, selectOtherMonths: true, showButtonPanel: true, showOn: 'focus' });
        $(".datefield").datepicker('option', '{showAnim: slideDown}');
    } catch (err) { }
    try {
        $(".datefield").attr('autocomplete', 'off');
    } catch (err) { }
    
    $("a[rel='colorbox_local_video']").colorbox({
        transition: "none",
        inline: true,
        href: "#video_frame",
        innerWidth: "480",
        innerHeight: "360",
        rel: 'nofollow',
        onOpen: loadJWPlayer,
        onCleanup: unloadJWPlayer
    });
    
    $("a[rel='colorbox_video']").colorbox({
        transition: "none",
        inline: true,
        iframe: "#video_frame",
        innerWidth: "480",
        innerHeight: "360",
        rel: 'nofollow'
    });
}

function loadJWPlayer() {
    jwplayer("video_frame").setup({
        autostart: true,
        file: this.href,
        width: 480,
        height: 360,
        flashplayer: applicationUrl + "/scripts/jwplayer/player.swf"
    });
}

function unloadJWPlayer() {
    var frame = $('#video_frame');
    frame.html('');
    frame.hide();
}
