$(this).ready(function() { 
    $('a[rel=lightbox]').lightbox({
        overlayOpacity:             0.5,
		fileLoadingImage :          xopieCDN + "libs/jquery/jquery.lightbox/images/loading.gif",
		fileBottomNavCloseImage :   xopieCDN + "libs/jquery/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();
	}
});

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 fitFlashSize(movie) {
	var hasTGet = ("TGetProperty" in movie);
	var w, h, ratio, success = false;

	try {
		if (hasTGet &&  movie.TGetProperty("/", 8) != undefined) {
			w = movie.TGetProperty("/", 8);
			h = movie.TGetProperty("/", 9);

			if (w > 0 && h > 0) {
				ratio = w / h;
				$(movie).width($(movie).parent().width());
				$(movie).height($(movie).parent().width() / ratio);
				success = true
			}
		}
	} catch (err) {
		//none
	}

	if (!success) {
		setTimeout(function() { fitFlashSize(movie); }, 100);
	}
}

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

	return true;
}

function toggleCountry(objSelect, strProvinceId, blnPersist) {
    objSelect = $(objSelect);
	var objProvince = $(strProvinceId);
	var strCode = objSelect.children(":selected").attr("rel");
	var blnFound = false;
	var strProvince;

	if (objProvince) {
		strProvince = objProvince.val();

		objProvince.parent().children("select").each(function (i) {
			if ($(this).attr("id") == strCode + "." + objProvince.attr("id")) {
				$(this).show();
				blnFound = true;

				if (blnPersist) {
					$(this).val(strProvince);
				} else {
					$(this).val("");
				}
			} else {
				$(this).hide();
			}                    
		});

		if (blnFound) {
			objProvince.hide();
		} else {
			objProvince.show();
		}
	}
}
