﻿
var iStartSlide = 0;

$(document).ready(function() {

	$("form")[0].onclick = function(e) {
		e = e || event;
		var el = e.srcElement || e.target;
		if (el.tagName == 'INPUT' && el.type == 'checkbox') {
			el.parentNode.className = el.checked ? 'checked' : '';
		}
	};


	jQuery(function($) {
		var iconImage = $("div#iconImage img").get(0);
		var logoImage = $("div#productLogo img").get(0);
		var logoHeight = 0;
		if (logoImage) {
			logoHeight = logoImage.height;
		}


		if (iconImage) {
			var cssObj = {
				marginTop: -iconImage.height - logoHeight - 49
			}

			var newsDiv = $("div.productImages div.news").get(0);
			if (newsDiv) {
				$(newsDiv).css(cssObj);
			}
		}
	});

	$("li#tabBrands").toggle(function() {
		$("div#assortment").animate({ height: "hide" }, 200);
		$("li#tabAssortment").removeClass("selectedTab");
		$("div#brands").animate({ height: "show" }, 200);
		$("li#tabBrands").addClass("selectedTab");
	}, function() {
		$("div#brands").animate({ height: "hide" }, 200);
		$("li#tabBrands").removeClass("selectedTab");
		return false;
	});

	$("li#tabAssortment").toggle(function() {
		$("div#brands").animate({ height: "hide" }, 200);
		$("li#tabBrands").removeClass("selectedTab");
		$("div#assortment").animate({ height: "show" }, 200);
		$("li#tabAssortment").addClass("selectedTab");
		$("div#closeSortiment").show();

	}, function() {
		$("div#closeSortiment").hide();
		$("div#assortment").animate({ height: "hide" }, 200);
		$("li#tabAssortment").removeClass("selectedTab");

		return false;
	});

	$(".closeTab a").click(function() {
		$("div#closeSortiment").hide();
		$(this).parent().parent().animate({ height: "hide" }, 200);
		$("li#tabBrands").removeClass("selectedTab");
		$("li#tabAssortment").removeClass("selectedTab");
		return false;
	});

	if (typeof sIFR == "function") {
		sIFR.replaceElement(named({ sSelector: "h2", sFlashSrc: "/Cervera/Units/Flash/Galliard.swf", sColor: "#222222", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=0" }));
		sIFR.replaceElement(named({ sSelector: "h3.green", sFlashSrc: "/Cervera/Units/Flash/Galliard.swf", sColor: "#7FAE36", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=0" }));
		sIFR.replaceElement(named({ sSelector: "h4", sFlashSrc: "/Cervera/Units/Flash/Galliard-bold2.swf", sColor: "#333333", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=0" }));
		sIFR.replaceElement(named({ sSelector: "h5", sFlashSrc: "/Cervera/Units/Flash/Galliard.swf", sColor: "#FFFFFF", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=0" }));
		sIFR.replaceElement(named({ sSelector: "p.boxText", sFlashSrc: "/Cervera/Units/Flash/Galliard.swf", sColor: "#222222", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=0" }));
		sIFR.replaceElement(named({ sSelector: "span.smallHeading", sFlashSrc: "/Cervera/Units/Flash/Galliard-bold2.swf", sColor: "#222222", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=3" }));
		sIFR.replaceElement(named({ sSelector: "span.largeHeading", sFlashSrc: "/Cervera/Units/Flash/Galliard-bold2.swf", sColor: "#222222", sLinkColor: "#8e003c", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 0, nPaddingBottom: 0, sWmode: "transparent", sFlashVars: "textalign=left&offsetTop=3" }));
	};

	$("a.jqModal").click(function() {
		$("select").hide();
	})

	$("#btnCloseSlideShow").click(function() {
		$("select").show();
	})

	$("#btnClose").click(function() {
		$("select").show();
	})

	$("a.slideShow").click(function() {
		var oparent = $(this).parent().get(0);
		var arrChilds = $(".thumbWrapper > div");
		for (var i = 0; i < arrChilds.length; i++) {
			if (arrChilds[i] == oparent) {
				iStartSlide = i;
				break;
			}
		}
	})

	//    $('#imgContainer').cycle({
	//        fx: 'scrollHorz',
	//        speed: 400,
	//        prev: '#prev1',
	//        next: '#next1',
	//        startingSlide: iStartSlide,
	//        timeout: 0
	//    });

	//var myOpen = function(hash) { hash.w.css('opacity', 0.99).show(); };
	//$('#video').jqm({ onShow: myOpen });

	//var myClose = function(hash) { hash.w.fadeOut('2000', function() { hash.o.remove(); }); };
	//$('#video').jqm({ onHide: myClose });

	$("#dialog").jqm();
	$("#video").jqm();

	//$('#dialog').jqm({ ajax: '/Cervera/Templates/SlideShow.aspx', trigger: 'a.slideShow' });

	// ***** SLIDESHOW *****

	jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
		return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	};

	$('#slideshow').serialScroll({
		items: 'li',
		prev: '.slideLeft a',
		next: '.slideRight a',
		offset: 0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start: iStartSlide, //as we are centering it, start at the 2nd
		duration: 800,
		force: true,
		stop: true,
		lock: false,
		cycle: true, //don't pull back once you reach the end
		easing: 'easeOutQuart', //use this easing equation for a funny effect
		jump: true //click on the images to scroll to them
	});


	$(".faqQuestion span").toggle(function() {
		$(this).parent().next().show();
		$(this).addClass("selected");
	}, function() {
		$(this).parent().next().hide();
		$(this).removeClass("selected");
	})

	$("table.giftFilter label").click(function() {
		var tdList = $("table.giftFilter td");
		for (i = 0; i < tdList.length; i++) {
			tdList[i].className = "";
		}
		var oparent = $(this).parent().get(0);
		oparent.className = "selected"
	})

	var radioList = $("table.giftFilter input");
	for (i = 0; i < radioList.length; i++) {
		if (radioList[i].checked) {
			radioList[i].parentNode.className = "selected"
		}
		else {
			radioList[i].parentNode.className = ""
		}
	}

});

function getPassWord(id) {

	var email = $get(id).value;
	CerveraEpi.Cervera.Util.Service.SendNewPassword(email, getPassWord_Callback);

}

function getPassWord_Callback(result) {

	if (result) {
		$get('emailSent').style.display = 'block';
		$get('emailError').style.display = 'none';

		$get('pwdBox').style.display = 'none';
		$get('pwdBtn').style.display = 'none';
		$get('pwdTxt').style.display = 'none';

	} else {
		$get('emailError').style.display = 'block';
		$get('emailSent').style.display = 'none';
	}
}

function createWishList() {
	alert("Create Wishlist")
}

function ClientButton_Click(arg) {
	document.getElementById("Hidden1").value = arg;
}

function gotoURL(val) {
	//self.location.href = val;
	location.href = val;
}

function openPrint(val) {
	window.open(val, "Print", "width=650,height=400,toolbar=0,menubar=0,scrollbars=1", true);
}

function getDays(sender) {
	switch (sender.selectedIndex) {
		case 0: renderDays(31);
			break;
		case 1: renderDays(28);
			break;
		case 2: renderDays(31);
			break;
		case 3: renderDays(30);
			break;
		case 4: renderDays(31);
			break;
		case 5: renderDays(30);
			break;
		case 6: renderDays(31);
			break;
		case 7: renderDays(31);
			break;
		case 8: renderDays(30);
			break;
		case 9: renderDays(31);
			break;
		case 10: renderDays(30);
			break;
		case 11: renderDays(31);
			break;

	}
}

function renderDays(num) {
	var dSelect = $(".ddlDay").get(0);
	var iSel = dSelect.selectedIndex;
	if (iSel > num) iSel = num;
	dSelect.options.length = 0;
	for (var i = 0; i < num; i++) {
		var elOptNew = document.createElement('option');
		elOptNew.text = i + 1;
		elOptNew.value = i + 1;
		dSelect.add(elOptNew);
	}
	dSelect.selectedIndex = iSel;
}
