$(function() {
	$("body").addClass("has-js");
	
	$('a.tandcs, #codeLocate a').openDOMWindow({
	    height: null,
	    width: 790,
	    positionType: 'absolute',
	    positionTop: 130,
	    positionLeft: 40,
	    eventType: 'click',
	    loader: 1,
	    loaderImagePath: '/Content/images/animationProcessing.gif',
	    loaderHeight: 16,
	    loaderWidth: 17,
		windowPadding: 0,
	    windowSource: 'ajax',
	    windowHTTPType: 'post',
		borderColor: '#b28b32',
		borderSize: '3'
	});
	$('#info_one a').openDOMWindow({
	    height: null,
	    width: 790,
	    positionType: 'absolute',
	    positionTop: 130,
	    positionLeft: 40,
	    eventType: 'click',
	    loader: 1,
	    loaderImagePath: '/Content/images/animationProcessing.gif',
	    loaderHeight: 16,
	    loaderWidth: 17,
		windowPadding: 0,
	    windowSource: 'ajax',
	    windowHTTPType: 'post',
		borderColor: '#b28b32',
		borderSize: '3',
		windowName: 'about-promotion'
	});
	$('#info_two a').openDOMWindow({
	    height: null,
	    width: 790,
	    positionType: 'absolute',
	    positionTop: 130,
	    positionLeft: 40,
	    eventType: 'click',
	    loader: 1,
	    loaderImagePath: '/Content/images/animationProcessing.gif',
	    loaderHeight: 16,
	    loaderWidth: 17,
		windowPadding: 0,
	    windowSource: 'ajax',
	    windowHTTPType: 'post',
		borderColor: '#b28b32',
		borderSize: '3',
		windowName: 'pretty-prizes'
	});
	
	
	
	
	
	
	$('#info_tri a').openDOMWindow({
	    width: 790,
		height: 1120,
	    positionType: 'absolute',
	    positionTop: 130,
	    positionLeft: 40,
	    eventType: 'click',
	    loader: 1,
	    loaderImagePath: '/Content/images/animationProcessing.gif',
	    loaderHeight: 16,
	    loaderWidth: 17,
		windowPadding: 0,
	    windowSource: 'iframe',
	    windowHTTPType: 'post',
		borderColor: '#b28b32',
		borderSize: '3',
		isKiss:1
	});
	
	$('#info_quad a, .make-up-tips').openDOMWindow({
	    height: null,
	    width: 790,
	    positionType: 'absolute',
	    positionTop: 130,
	    positionLeft: 40,
	    eventType: 'click',
	    loader: 1,
	    loaderImagePath: '/Content/images/animationProcessing.gif',
	    loaderHeight: 16,
	    loaderWidth: 17,
		windowPadding: 0,
	    windowSource: 'ajax',
	    windowHTTPType: 'post',
		borderColor: '#f7c2d8',
		borderSize: '3',
		windowName: 'secret-tips'
	});
	
	$('.close').closeDOMWindow({
		eventType:'click'
	});
	
	if (document.body.id == "home") {
		var params = { loop:false, wmode:"transparent" };
		swfobject.embedSWF("/Content/swf/lips.swf", "lips", "225", "575", "9.0.0", "/swf/expressInstall.swf", null, params);
	}
	
	if (document.body.id == "claim") {
	
		$(".carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			circular: false
		});	
	
		$(".carousel").data("credits", Number($("#user_credits").text()));

		$(".carousel").bind("addItem", function(event, item) {
			var dataFetched = $(this).data();
			if (dataFetched['credits'] > 0) {
				$("input", item).val( Number($("input", item).val()) + 1 );
				$(this).trigger("useCredit");
			}
		});

	
		$(".carousel").bind("removeItem", function(event, item) {
			var dataFetched = $(this).data();
			if (Number($("input", item).val()) > 0) {
				$("input", item).val( Number($("input", item).val()) - 1 );
				$(this).trigger("addCredit");
			}
		});	
	
		$(".carousel").bind("useCredit", function() {
			var dataFetched = $(this).data();
			if (dataFetched['credits'] > 0) {
				$(this).data("credits", dataFetched['credits'] - 1);
			}
			$(this).trigger("checkCredit");
		});
	
		$(".carousel").bind("addCredit", function() {
			var dataFetched = $(this).data();
			$(this).data("credits", dataFetched['credits'] + 1);
			$(this).trigger("checkCredit");
		});
	
		$(".carousel").bind("checkCredit", function() {
			var dataFetched = $(this).data();
			if (dataFetched['credits'] > 0) {
				$(".add span", this).removeClass("disabled");
			} else {
				$(".add span", this).addClass("disabled");
			}
			$("li", this).each(function() {
				if ( Number($("input", this).val()) > 0 ) {
					$(".remove span", this).removeClass("disabled");
				} else {
					$(".remove span", this).addClass("disabled");
				}
			});
		});
	
	
		$(".carousel li").each(function() {
			$(".add", this).click(function() {
				var dataFetched = $(".carousel").data();
				if (dataFetched['credits'] > 0) {
					$(".carousel").trigger("addItem", $(this).parent());
				}
				return false;
			}); 
			$(".remove", this).click(function() {
				var dataFetched = $(".carousel").data();
				$(".carousel").trigger("removeItem", $(this).parent());
				return false;
			});
		});
		
		$(".carousel").trigger("checkCredit");
	}
	
	if (document.body.id == "entry") {
		$("#in_code").focus();
		var submit_attempt = false;
		
		$("#container form").submit(function() {
			if ($("#in_code").attr("value")=="") {
				if (!submit_attempt) {
					$(this).find("legend").after("<div class=\"error box\"><div><p><strong><em>Whoops!</em> Please make sure you&rsquo;ve entered your pack code</strong></p></div></div>");
					$("#in_code").focus();
					submit_attempt = true;
				}
				return false;
			}
		});
	}
	
	$("#l_password").click(function() {
		$("#in_is-registered").attr("checked", "checked");
	});
	
	$("#in_password").click(function() {
		$("#in_is-registered").attr("checked", "checked");
	});
	
	$("#in_is-registered").click(function() {
		$("#in_password").focus();
	});
	

});
