$(this).ready(function() { 
    $('a[@rel*=lightbox]').lightbox({
        overlayOpacity:             0.5,
		fileLoadingImage :          xopieCDN + "templates/" + xopieTemplate + "/js/jquery.lightbox/images/loading.gif",
		fileBottomNavCloseImage :   xopieCDN + "templates/" + xopieTemplate + "/js/jquery.lightbox/images/closelabel.gif"
    });

    $("#q").change(function() {
        $(this).attr("changed", true);
    });

    $("#q").focus(function() {
        if (!$(this).attr("changed")) { $(this).val("");}
    });

	if ($("#supportNav .languageSelection ul").length) {
		$("#supportNav .languageSelection ul a[class!=active]").each(function(i) {
			$(this).parent().hide();
		});
		
		$("#supportNav .languageSelection ul").mouseover(function() {
			$(this).find("li").css("display", "list-item");
			$(this).parents(".languageSelection").addClass("open");
		});

		$("#supportNav .languageSelection ul").mouseout(function() {
			$("#supportNav .languageSelection a[class!=active]").each(function(i) {
				$(this).parent().css("display", "none");
			});

			$(this).removeClass("open");
		});

		$(window).resize(function(){
			initLSPos();
		});

		initLSPos();
	}

	if ($("#sideNav").length) {
		$("#sideNav li").mouseover(function() {
			$(this).addClass("sfhover");
		});

		$("#sideNav li").mouseout(function() {
			$(this).removeClass("sfhover");
		});
	}
});

function initLSPos() {
	$("#supportNav .languageSelection ul").css("top", $("#supportNav .languageSelection img.dummy").offset().top + "px");
	$("#supportNav .languageSelection ul").css("left", ($("#supportNav .languageSelection img.dummy").offset().left + $("#supportNav .languageSelection img.dummy").width() - $("#supportNav .languageSelection ul").width()) + "px");
}

function expandct(sId, e) {
    $("#" + sId).css("overflow-y", "hidden");
    $("#" + sId).css("height", "auto");
    $("#" + sId + "_expand").hide();
    $("#" + sId + "_collapse").show();
    if (e) { e.cancelBubble=true;e.returnValue=false;return false; }
}

function collapsect(sId, e) {
    $("#" + sId).css("overflow-y", "hidden");
    $("#" + sId).css("height", "150px");
    $("#" + sId + "_expand").show();
    $("#" + sId + "_collapse").hide();
    if (e) { e.cancelBubble=true;e.returnValue=false;return false; }
}

function initFaqs() {
    var fnToogle = function(e) {
        if ($(this).parents(".faqItem").find(".faqAnswer:hidden").length) {
            $(".faqAnswer").slideUp(300);
            $(this).parents(".faqItem").find(".faqAnswer").slideDown(400);
        }

        if (e) { e.cancelBubble=true;e.returnValue=false;return false; }
    };
   
    $(".faqQuestion a").each(function (i) {
        $(this).parents(".faqItem").find(".faqAnswer").hide();
        $(this).click(fnToogle);
    });
}

function writeFlash(sId, sImg, iW, iH) {
	var h = Math.ceil((iH * $("#" + sId).width()) / iW);
	$("#" + sId).flash({
		width: "100%",
		height: h + "px",
		wmode: "transparent",
		src: sImg
	});
}

function IFrmPay(oFrm, bValidated, e) {
	if (bValidated) {
		oFrm.target = "paymentIFrm";
		$(".formFeedbackError").slideUp(200);
		$("#checkoutBox").slideUp(200);
		$("#paymentBox").slideDown(200);
	}

	return true;
}
