/* clearTimeOut Keeps the Menu Open */
$clearTimeOut = 0;
// Keep the Menu Open if we're highlighting a sub-menu item
function keep_open()
	{$clearTimeOut = 0;}
// Begin the closing procedure with a countdown
function close_menu($id)
	{
		$clearTimeOut = 1;
		$temp_timeout = setTimeout("close_menu_final("+$id+");", 250);					
	}			
// Do the final menu clearing
function close_menu_final($id)
	{
		// Check whether or not we've scrolled over a menu item
		if($clearTimeOut == 1)
			{
				$use_id = "#sub-menu-"+$id;
				setTimeout(function(){$($use_id).parent().children("a").removeClass("hover");}, 250);
				$($use_id).slideUp({duration: 250});
			}
	}

$move_by = 660;
$frame_left = 0;
$frame_no = 1;
$.checkoutopen = 0;
function set_cart_functions()
	{
		//Don't Send us ANYWHERE
		$("[id^=add-], [id^=remove-]").live("click", function(){return false;});
		$(".checkout").live("click", function(){return false;});
		$("#header-cart-btn").live("click", function(){return false;});
		$("#close-header-cart").live("click", function(){return false;});
		//Set all the functions
		$("[id^=add-], [id^=remove-]").live("click", function(){update_cart($(this).attr("id"));});
		$(".checkout").live("click", function(){begin_checkout();});
		$("#header-cart-btn").live("click", function(){cart_show_hide();});
		$("#close-header-cart").live("click", function(){cart_hide();});
	}
function cart_show_hide()
	{	
		if($("#header-cart-form").attr("class").indexOf("no_display") !== -1 || $.checkoutopen == "1")
			{
				$("#header-cart-form").fadeIn("slow").removeClass("no_display");
				container_dim();
				if($.checkoutopen == "1")
					{
						$("#cart-form").slideUp("fast");
						$("#cart-form-alert").html("<p class=\"success\">Fetching Your Cart Details</p>").fadeIn("slow");
						$post_page = "shoppingList.cfm?fetch=1";
						$.post($post_page, {}, 
							function(data){
								$("#cart-form-alert").slideUp("fast");
								$("#cart-form").html(data).fadeIn("fast");
								$.checkoutopen = 0;
							});
		
					}
			}
		else
			{
				container_lighten();
				$("#header-cart-form").fadeOut("slow").attr("class", "no_display");
			}
		return false;
	}
function switch_slides($current_id, $next_id)
	{	
		$old_post_id = $current_id.replace("image-", "post-");
		$new_post_id = $next_id.replace("image-", "post-");
		
		$($current_id).fadeOut("fast");
		$($next_id).addClass("floatleft");
		$($old_post_id).slideUp("slow");
		
		setTimeout(
			function()
				{
					$($next_id).fadeIn("slow");
					//$($next_id+" img").css("left", (0.5*(960-$($next_id+" img").attr("width")))+"px")
					$($new_post_id).slideDown("slow").addClass("feature-post-content").addClass("clearfix");
					$.busy = 0;
				}
		,100);
	}
function cart_hide()
	{		
		container_lighten();
		$("#header-cart-form").fadeOut("slow").attr("class", "no_display");
		return false;
	}
function update_cart($id)
	{
		//Scroll to the top of the page
		$("html").animate({scrollTop: $("#logged-in-container").offset().top}, 1000);

		//Alert us
		$("#cart-form-alert").html("<div class=\"cart-notice\">Updating Your Cart</div>").fadeIn("slow");

		//Hide the form
		$("#cart-form").slideUp("fast");
		
		//Determin of we must show the form if it's not showing already
		$original_class = $("#header-cart-form").attr("class");
		
		if($("#header-cart-form").attr("class") == "no_display")
			{
				$(".cart-tip").fadeOut();
				$("#header-cart-form").fadeIn("slow").removeClass("no_display");
				$(".cart-tip").fadeIn("slow");
				container_dim();
			}
			
		//Set Id and Type of Product
		if($id.indexOf("remove-") !== -1)
			{
				$id = $id.replace("remove-", "");
				$delete = 1;
			}
		else
			{
				$id = $id.replace("add-", "");
				$delete = 0;
			}
		$theme_options_href_id = "#purchase-options-href-"+$id.toString().substr(0, 4);
		$theme_options_div_id = "#purchase-options-div-"+$id.toString().substr(0, 4);

		$($theme_options_href_id).attr("class", "pricing-small");
		$($theme_options_div_id).slideUp("fast");
		$($theme_options_href_id).html("Add to Cart");

		//Start Our Ajax
		$post_page = "update_cart_ajax.cfm";
		$.post($post_page, {Id: $id, remove: $delete}, 
			function(data){										  
					//Update the Cart
					$("#cart-form-alert").slideUp("fast");
					//Hide the Form
					$("#header_login_form").fadeOut("fast").addClass("no_display");
					//Hide the Cart Summary
					$("#cart-li").slideUp("slow");
					//Reshow the Form
					$("#cart-form").html(data).fadeIn("fast");
					setTimeout(function(){$("#cart-li").remove();}, 200);
					if(document.getElementById("theme-for-twenty"))
						{
							// Refresh the $20 theme panel
							$.post("fetch_theme_for_twenty.cfm", {},function(data){$("#theme-for-twenty").fadeOut("fast").html(data).fadeIn("fast");});
						}
					$.post("fetch_cart_details.cfm?fetch=1", {},
						   function(data)
							{
								$("#login-menu").append(data);
								//setTimeout(function(){}, 250);
								$("#cart-li").slideDown("slow")
								if($original_class == "no_display")
									{$.clearCart = setTimeout(function(){$("#header-cart-form").fadeOut("slow").addClass("no_display"); $("#cart-form-alert").fadeOut("slow"); container_lighten();},  2500);}
								else
									{setTimeout(function(){$("#cart-form-alert").fadeOut("slow")}, 750);}								
								return false;
							}									
					);
		});
	}
function begin_checkout()
	{	
		if($("#header-cart-form").attr("class").indexOf("no_display") !== -1 || $.checkoutopen == "1")
			{
				//Alert us
				$("#cart-form-alert").html("<div class=\"cart-notice\">Redirecting to the Checkout Page</div>").fadeIn("slow");		
				$("#cart-form").html("");
				$("#header-cart-form").fadeIn("slow");
			}
		else
			{
				$("#cart-form-alert").fadeOut("slow").html("<div class=\"cart-notice\">Redirecting to the Checkout Page</div>").fadeIn("slow");
				$("#cart-form").slideUp("slow");
			}
		container_dim();
		setTimeout(function(){window.location=("checkout.cfm");}, 1500);
		return false;
	}
function container_dim()
	{setTimeout(function(){$(".container, .splurb-list-container, .footer_container").animate({opacity: 0.15}, 500);}, "650");}
function container_lighten()
	{setTimeout(function(){$(".container, .splurb-list-container, .footer_container").animate({opacity: 1.0}, 150);}, "650");}
function match_image_height($i){	
	if($("#expand-product-window").html() !== "Expand Screenshot Window")
		{
			$new_height = $("#image_container div img:nth-child("+$i+")").height();
			if($new_height > 600) 
				{$new_height = 600;}
			$(".screenshot-container").animate({height: $new_height}, 150);
			$(".prev-screenshot, .next-screenshot").animate({top: (($new_height/2)-12)}, 400);
		}
	else
		{
			$(".screenshot-container").animate({height: 460}, 150);
			$(".prev-screenshot, .next-screenshot").animate({top: 220}, 400);
		}
	return false;
}
/* Lightbox Gallery Function */
$(document).ready(function()
	{
		/**************/
		/* MENU STUFF */
		$.open_menu = 0;
		$("a[id^='main-menu-item-']").mouseover(function(){
			// Start the timeout to keep the menu open
			$(this).addClass("hover")
			keep_open()
			// Create the id to ref the submenu
			$sub_menu_id = $(this).attr("id").replace("main-menu-item-", "");
			$id = "sub-menu-"+$sub_menu_id;
			$new_sub_menu = "#"+$id;
			
			if($.open_menu !== $new_sub_menu)
				{$(".sub_menu").slideUp("fast");}
		
			// fade in the submenu
			$($new_sub_menu).slideDown({duration: 250});
			$.open_menu = $new_sub_menu;
		});
		$("[id^='sub-menu-']").mouseover(function(){
			// Start the timeout to keep the menu open
			keep_open()														
		});
		$("[id^='sub-menu-']").mouseout(function(){
			// Create the id to ref the submenu
			$sub_menu_id = $(this).attr("id").replace("sub-menu-", "");
			// Start the cloding process
			close_menu($sub_menu_id);				
		});
		$("a[id^='main-menu-item-']").mouseout(function(){
			// Create the id to ref the submenu
			$sub_menu_id = $(this).attr("id").replace("main-menu-item-", "");
			// Start the cloding process
			close_menu($sub_menu_id);								
		});
		
		/********************/
		/* THEME SHOP STUFF */
		$frame_left = 0;
		$frame_no = 1;
		$start_middle = 0;
		$move_by = $("#image_container div").width();
		$max_clicks = $("#image_container div").children().size(); 
		$("#image_container div").animate({left: 0}, 250);
		/* Kudos to Rob MacKay [http://www.twitter.com/svgrob] for suggesting that we don't have to put a static style="width: 3960px" attribute in the div tag */
		$imgCont = $move_by * $max_clicks; 
		
		$("#image_container div").css({width: $imgCont});
		$(".prev-screenshot").click(function()
			{
				/* Set the new position & frame number */
				$new_frame_no = (($frame_no/1)-1);
				$new_left = (($frame_left/1) + $move_by);
				/* Check if we're moving too far over */
				$max_clicks = $("#image_container div").children().size();
				if($new_frame_no <= 0)
					{
						/* Move the images all the way left, minus one frame */
						$new_left = -($move_by*$max_clicks)+$move_by;
						$new_frame_no = $max_clicks;
					}
				$new_left_attr = $new_left+"px";
				$("#image_container div").animate({left: $new_left_attr}, 250);
				$frame_left = $new_left;
				$frame_no = $new_frame_no;
				match_image_height($frame_no);
				return false;
			});
		$(".next-screenshot").click(function()
			{
				/* Set the new position & frame number */
				$new_frame_no = (($frame_no/1)+1);
				$new_left = (($frame_left/1) - $move_by);
				/* Check if we're moving too far over */
				$max_clicks = $("#image_container div").children().size();
				if($new_frame_no > $max_clicks)
					{		
						/* Move all the way right, to the beginning*/
						$new_left = 0;
						$new_frame_no = 1;
					}			
				$new_left_attr = $new_left+"px";
				$("#image_container div").animate({left: $new_left_attr}, 250);
				$frame_left = $new_left;
				$frame_no = $new_frame_no;
				match_image_height($frame_no);
				return false;
			});	
		$("#expand-product-window").click(function(){
			if($(this).html() == "Expand Screenshot Window")
				{
					$new_height = $("#image_container div img").height();
					if($new_height > 600) 
						{$new_height = 600;}
					$(".screenshot-container").animate({height: $new_height}, 150);
					$(".prev-screenshot, .next-screenshot").animate({top: (($new_height/2)-12)}, 400);
					$(this).html("Contract Screenshot Window");
				}
			else
				{
					$(".screenshot-container").animate({height: 460}, 150);
					$(".prev-screenshot, .next-screenshot").animate({top: 120}, 400);
					$(this).html("Expand Screenshot Window");
				}
			return false;
		});
		
		$(".view-all-features").click(function(){
				if($(this).html() == "View All Features")
					{
						$(this).html("Hide Extra Features");
						$("[id^=hidden-features-]").slideDown("fast");
					}
				else
					{
						$(this).html("View All Features");
						$("[id^=hidden-features-]").slideUp("fast");
					}				
				return false;
			});
		$("[id^=theme-screenshots-href-]").click(function(){
				$id = $(this).attr("id").replace("theme-screenshots-href-", "");
				$screen_tab_id = "#theme-screenshots-tab-" + $id;
				$video_href_id = "#theme-video-" + $id;
				$video_tab_id = "#theme-video-tab-" + $id;
				
				$($video_href_id).parent().removeClass("selected");
				$(this).parent().addClass("selected");
				$($video_tab_id).fadeOut("fast").addClass("no_display");	
				$($screen_tab_id).fadeIn("slow").removeClass("no_display");	
				return false;
			});
		
		$("[id^=theme-video-]").click(function(){
				$id = $(this).attr("id").replace("theme-video-", "");
				$screen_href_id = "#theme-screenshots-href-" + $id;
				$screen_tab_id = "#theme-screenshots-tab-" + $id;
				$video_tab_id = "#theme-video-tab-" + $id;
				
				$($screen_href_id).parent().removeClass("selected");
				$(this).parent().addClass("selected");
				$($screen_tab_id).fadeOut("fast").addClass("no_display");	
				$($video_tab_id).fadeIn("slow").removeClass("no_display");	
				return false;
			});
		$("[id^=theme-image-]").click(function(){
			$img_id = "#"+$(this).attr("id")+" > img";
			$new_src = $($img_id).attr("src");
			$old_src = $("#theme-screenshot").attr("src");
			$("#theme-screenshot").attr("src", $new_src);
			$($img_id).fadeOut("fast");
			setTimeout(function()
				{
					$($img_id).attr("src", $old_src);
					setTimeout(function()
						{
							$($img_id).fadeIn("slow");
						}, 250);
				},
			750);
			return false;
		});
		/***************/
		/* INDEX STUFF */
		$.selected_slide = 1;
		$.selected_tab = 1;
		$max_slides= $(".theme-screens div").children().size(); 
		setInterval(
			function()
				{
					$current_id = "#index_theme_"+$.selected_slide;
					$.selected_slide++
					if($max_slides == $.selected_slide)
						{$.selected_slide = 1}
					$new_id = "#index_theme_"+$.selected_slide;
					$($current_id).fadeOut({duration: 750});
					$($new_id).fadeIn({duration: 2000});
				}
			,4000
		);
		$("[id^=index-tab-]").click(function(){
		
			$old_tab_id = "#index-tab-"+$.selected_tab;
			$old_content_id = "#index-content-"+$.selected_tab;
			$($old_content_id).fadeOut("fast").attr("class", "no_display");
			
			
			$id = $(this).attr("id").replace("index-tab-", "");
			
			$new_tab_id = "#index-tab-"+$id;
			$new_content_id = "#index-content-"+$id;
			$new_li_id = "#index-li-"+$id;
			
			$(".selected").removeClass("selected");
			$($new_li_id).fadeTo(200, 0.05);
			if($id == 4)
				{$use_class = "selected last";}
			else
				{$use_class = "selected";}
			setTimeout(function(){$($new_li_id).attr("class", $use_class);}, 300); 
			setTimeout(
			   function()
					{
						$($new_content_id).fadeIn("slow");
						$($new_li_id).fadeTo(2000, 1);
					}
			, 400);
			
			$.selected_tab = $id;
			return false;
		});
		$("#index-next-theme").click(function(){
			$max_loop = ($("#feature-theme-list > li").length - 5);
			$interval = 500;
			$i = 2;
			$slideShow = setInterval(
				function(){
					$selector = "#feature-theme-list li:nth-child("+$i+")";					
					$($selector).fadeOut("slow");					
					$new_li = "#feature-theme-list li:nth-child("+($i + 3)+")";
					$old_last_li = "#feature-theme-list li:nth-child("+($i + 2)+")";
					$($old_last_li).removeClass("last");
					setTimeout(function(){$($new_li).fadeOut("fast").addClass("feature-theme").addClass("last").fadeIn("slow");}, 500);
					$i++;
					$interval += 150;
					if($i == $max_loop){ alert("STOP " + $i);}
					clearInterval($slideShow);
				},
				$interval)
			return false;
		});
		/**************/
		/* CART STUFF */
		$("#header-cart-form").mouseover(function(){
			if($.clearCart)						
				{clearTimeout($.clearCart)}
		});
		$("#terms").click(function(){
			if($(this).attr("checked"))
				{$("#buy_button").removeAttr("disabled");}
			else
				{$("#buy_button").attr("disabled", "1");}
		});
		$("a[id^=purchase-options-href-]").click(function(){
			$id = $(this).attr("id").replace("href-", "div-");
			$use_id = "#"+$id;
			if($(this).attr("class") == "pricing-small")
				{
					$($use_id).slideDown("fast");
					$(this).attr("class", "pricing-small-active");
					$(this).html("Cancel");
				}
			else
				{
					$(this).attr("class", "pricing-small");
					$($use_id).slideUp("fast");
					$(this).html("Add to Cart");
				}
			return false;
		});
		
		/********************/
		/* VALIDATION STUFF */
		$("#myprofile-form").submit(function(){
			$error = "";
			if($("#checkout_firstname").attr("value") == "")
				{$error += "\n - Fill in your first name.";}
			if($("#checkout_surname").attr("value") == "")
				{$error += "\n - Fill in your surname.";}
			if($("#checkout_email").attr("value") == "")
				{$error += "\n - Fill in a valid email address.";}
			if($("#checkout_password").attr("value") !== "" && ($("#checkout_password").attr("value").length < 6))
				{$error += "\n - Fill in a password at least 6 digits long.";}
			if($("#checkout_password").attr("value") !== "" && ($("#checkout_password").attr("value") !== $("#checkout_confirm_password").attr("value")))
				{$error += "\n - Match your Password in the 'Confirm Password' field.";}
			if($error)
				{
					alert("Please correct the following:\n"+$error);
					return false;
				}
			else
				{return true;}
		});
		
		$("#affiliate-special-form").submit(function(){
			$error = "";
			if($("#special-headline").attr("value") == "")
				{$error += "\n - Fill in a name for your 25:25 Special.";}
			if($("#date-from").attr("value") == "" || $("#date-to").attr("value") == "")
				{$error += "\n - Fill in a Start and End Date";}
			if(isNaN($("#discount-percent").attr("value")) || $("#discount-percent").attr("value") == "")
				{$error += "\n - Fill in a discount Percentage and Make sure it's a Number.";}
			if($error)
				{
					alert("Please correct the following:\n"+$error);
					return false;
				}
			else
				{return true;}
		});
		
		
		
		$("#affiliate-register-form").submit(function(){
			$error = "";
			if($("#affiliate_firstname").attr("value") == "")
				{$error += "\n - Fill in your first name.";}
			if($("#affiliate_surname").attr("value") == "")
				{$error += "\n - Fill in your surname.";}
			if($("#affiliate_email").attr("value") == "")
				{$error += "\n - Fill in a valid email address.";}
			if($("#affiliate_website").attr("value") == "")
				{$error += "\n - Fill in your website.";}
			if($("#affiliate_password").attr("value") == "" || $("#affiliate_password").attr("value").length < 6)
				{$error += "\n - Fill in a password at least 6 digits long.";}
			if($("#affiliate_password").attr("value") !== $("#affiliate_confirm_password").attr("value"))
				{$error += "\n - Match your Password in the 'Confirm Password' field.";}
			if($("#agree_terms").attr("checked") == 0)
				{$error += "\n - Agree to the Terms and Conditions.";}
			if($error)
				{
					alert("Please correct the following:\n"+$error);
					return false;
				}
			else
				{return true;}
		});
		
		$("#affiliate-login-form").submit(function(){
			$error = "";
			if($("#affiliate_website").attr("value") == "")
				{$error += "\n - Fill in your website.";}
			if($error)
				{
					alert("Please correct the following:\n"+$error);
					return false;
				}
			else
				{return true;}
		});
		
		
		$("#checkout-register-form").submit(function(){
			$error = "";
			if($("#checkout_firstname").attr("value") == "")
				{$error += "\n - Fill in your first name.";}
			if($("#checkout_surname").attr("value") == "")
				{$error += "\n - Fill in your surname.";}
			if($("#checkout_email").attr("value") == "")
				{$error += "\n - Fill in a valid email address.";}
			if($("#checkout_password").attr("value") == "" || $("#checkout_password").attr("value").length < 6)
				{$error += "\n - Fill in a password at least 6 digits long.";}
			if($("#checkout_password").attr("value") !== $("#checkout_confirm_password").attr("value"))
				{$error += "\n - Match your Password in the 'Confirm Password' field.";}
			if($error)
				{
					alert("Please correct the following:\n"+$error);
					return false;
				}
			else
				{return true;}
		});
		
		/**********************/
		/* PROFILE AND HEADER */
		$("#add_special").click(function(){
			$("#affiliate_form").slideDown("slow");
			$("#add_special").fadeOut("slow");
			return false;
		});
		
		$("#cancel_add_special").click(function(){
			$("#affiliate_form").slideUp("slow");
			$("#add_special").fadeIn("slow");
			return false;
		});
		
		$(".delete-icon").click(function(){
			var delete_special = confirm("Are you sure you want to delete this special?");
			if(!delete_special)
				{return false;}
			else
				{return true;}
		});
		$("#header-login-btn, #close-login").click(function()
			{	
				
				if($("#header-cart-form").attr("class") !== "no_dispaly")
					{
						$(".cart-tip").fadeOut("slow");
						$("#header-cart-form").slideUp("slow").addClass("no_display");
					}
				if($("#header-login-btn").html() == "Logout")
					{
						container_dim();
						$("#login-menu").slideUp("fast");
					}
				else if($("#header_login_form").attr("class") == "no_display")
					{
						container_dim();
						$("#header_login_form").fadeIn("slow").removeClass("no_display");						
						$("#header-login-btn").html("Hide Form");
						return false;
					}				
				else
					{
						$("#login-form-alert").html("");
						$("#header_login_form").fadeOut("fast").addClass("no_display");
						$("#header-login-btn").html("Login");
						container_lighten();
						return false;
					}
			});
		
		$("#forget-me").click(function()
			{
				$("#login-menu").slideUp("fast");
				$post_page = "forget_me.cfm";
				$("#cookie-info").remove();
				$("#cart-li").remove();
				$.post($post_page, {}, function(data){$("#login-menu").slideDown("fast");});
				$.post("fetch_cart_details.cfm?fetch=1", {},
				function(data)
					{
						$("#login-menu").append(data).slideDown("fast");																	
						$("#cart-li").slideDown("slow");
					});
				return false;
			});
		$("a[id^=expand-href-]").click(function(){
			$id = $(this).attr("id").replace("expand-href-", "");
			$use_id = "#details-"+$id;
			if($(this).html() == "Expand")
				{
					$($use_id).slideDown("fast").addClass("clearfix");
					$(this).html("Collapse");
				}
			else
				{
					$($use_id).slideUp("fast");
					$(this).html("Expand");
				}
			return false;
		});
		$.selected_doc_tab = 1;
		$("[id^=documentation-href-]").click(function(){
				$id = $(this).attr("id").replace("documentation-href-", "");
				$old_href = "#documentation-href-"+$.selected_doc_tab;
				$old_tab = "#documentation-details-"+$.selected_doc_tab;				
				$new_href = "#documentation-href-"+$id;
				$new_tab = "#documentation-details-"+$id;
				
				$($old_href).parent().removeClass("selected");				
				$($new_href).parent().addClass("selected");
				
				$($old_tab).slideUp("fast");
				$($new_tab).slideDown("fast").addClass("clearfix");
				
				$.selected_doc_tab = $id;
				return false
			});
		$("[id^=show-hide-], [id^=tr-show-hide-]").live("click", function(){
				if($(this).attr("id").indexOf("tr") !== -1)
					{
						$tbody = "#"+$(this).attr("id").replace("tr-show-hide-", "body-");
						$href_id = "#"+$(this).attr("id").replace("tr-show-hide-", "show-hide-");
					}
				else
					{
						$tbody = "#"+$(this).attr("id").replace("show-hide-", "body-");
						$href_id = "#"+$(this).attr("id");
					}
					
				if($($href_id).html().indexOf("+ Expand") !== -1)
					{
						$($href_id).html("- Hide");
						$($tbody).fadeIn("slow");
					}
				else
					{
						$($href_id).html("+ Expand");
						$($tbody).fadeOut("fast");
					}
				return false;
			});
		
		$("[id^=checkout-tab-]").click(function()
			{
				if($(this).attr("id") == "checkout-tab-1")
					{
						$(this).addClass("register-button-active");
						$("#checkout-tab-2").removeClass("login-button-active");
						$("#checkout-content-1").slideDown("fast");
						$("#checkout-content-2").slideUp("fast");
					}
				else
					{
						$("#checkout-tab-1").removeClass("register-button-active");
						$(this).addClass("login-button-active");
						$("#checkout-content-1").slideUp("fast");
						$("#checkout-content-2").slideDown("fast");
					}
				return false;
			});
		$("#source_domain").keyup(function(){
			if(document.getElementById("colour"))
				{
					$use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+$(this).attr("value")+"/style.css\" />";
					$use_html += "\n<!--[if lte IE 8]><link href=\""+$(this).attr("value")+"/ie-style.css\" rel=\"stylesheet\" type=\"text/css\"><![endif]-->";
					$use_html += "\n<link rel=\"stylesheet\" type=\"text/css\" href=\""+$(this).attr("value")+"/color-styles/"+$("#colour").attr("value")+"/style.css\" />";
				}
			else
				{$use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+$(this).attr("value")+"/style.css\" />";}
			$("#source_code").attr("value", $use_html);
		});
		$("#colour").change(function(){
			$use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+$("#source_domain").attr("value")+"/style.css\" />";
			$use_html += "\n<!--[if lte IE 8]><link href=\""+$("#source_domain").attr("value")+"/ie-style.css\" rel=\"stylesheet\" type=\"text/css\"><![endif]-->";
			$use_html += "\n<link rel=\"stylesheet\" type=\"text/css\" href=\""+$("#source_domain").attr("value")+"/color-styles/"+$("#colour").attr("value")+"/style.css\" />";
			$("#source_code").attr("value", $use_html);
		});
		/*
		$("#login-post-form").submit(function()
			{	
				// Compile all the request details
				$email = $("#login_email").attr("value");
				$password = $("#login_password").attr("value");
				$rememberPassword = $("#rememberPassword").attr("checked");
				
				$post_page = "validate_login.cfm"
				// Perform the "Magic" which is just a bit of Ajax
				$("#login-form").slideUp("fast");
				$("#login-form-alert").html("<p class=\"success\">Validating Your Details</p>").fadeIn("slow");
				setTimeout(
					function(){$.post($post_page, {email: $email, password: $password, rememberPassword: $rememberPassword}, 
							function(data){
								$("#login-form-alert").removeClass("no_display").fadeIn("fast").html(data);
								if(data.indexOf("verified") !== -1)
									{
										setTimeout(
											function()
												{
													$("#header_login_form").fadeOut("fast").addClass("no_display");
													$("#header-login-btn").html("Logout");
													$("#cart-li").remove();
													$("#cookie-info").remove();
													$("#header-login-btn").attr("href", "logout.cfm");
													$("#login-menu").slideUp("fast");
													setTimeout(
														function()
															{
																$.post("fetch_login_details.cfm", {},function(data){$("#login-menu").prepend(data);});
																$.post("shoppingList.cfm?fetch=1", {},function(data){$("#cart-form").html(data);});
																container_lighten()
																$.post("fetch_cart_details.cfm?fetch=1", {},
																	function(data)
																		{
																			$("#login-menu").append(data).slideDown("fast");																	
																			$("#cart-li").slideDown("slow");
																		});
															}
														, 300);
												}
										, 700);
									}
								else
									{$("#login-form").slideDown("fast");}
						});}
				, 700);
				return false;
			});
		*/
		set_cart_functions();	
		/* Hotfix Listing*/
		$("[id^=hotfix-href-]").click(function()
			{
				$use_id = $(this).attr("id").replace("hotfix-href-", "#hotfix-details-");
				
				if($($use_id).attr("class") == "no_display")
					{$($use_id).slideDown("slow").removeClass("no_display");}
				else
					{$($use_id).slideUp("slow").addClass("no_display");}
				return false;
			});
		/* Tab Swapping */
		$.profiletab = 1;
		$tab_id = new Array();
		$old_tab_id = new Array();
		$check_load_page = new Array();
		$load_page = new Array();
		$("[id^=profile-tab-]").click(function()
			{
				/* Create the id to reference the content*/
				$id = this.id.toString().replace("profile-tab-", "");
				$old_tab_id[$id] = "#profile-content-" + $.profiletab;
				$tab_id[$id] = "#profile-content-" + $id;
				$check_load_page[$id] = "fetch-page-"+$id;
				$load_page[$id] = "#fetch-page-"+$id;
				// If we're clicking a new tab, fade it in.
				if($(".selected > a").attr("id") !== this.id)
					{
						//Fade the Old Form Out
				   		$($old_tab_id[$id]).slideUp("fast");
						
						//Fade the New Form out, Change it's Class, and Fade it in again
						$($tab_id[$id]).addClass("selected_tab").slideDown("fast");
												
						//Clear the Class of the Selected Tab
						$(".selected").attr("class", "")
						//Clear the Class of the New Tab						
						$(this).parent().attr("class", "selected")
						
						if(document.getElementById($check_load_page[$id]))
							{
								$post_page = $($load_page[$id]).html();
								$.post($post_page, {}, function(data)
								{									
									$($tab_id[$id]+" > div").html(data);
									$($tab_id[$id]+" > p").remove();
									$("#"+$check_load_page).attr("id", "");
									$(function(){$("[id^=banner-img-]").lightBox();});
								});
							}
					}
				$.profiletab = $id;
				return false;
			});
		$("[id^=validate-coupon]").click(function(){		
			$("#2-checkout-form").attr("action", "2checkout.cfm");
			$("#2-checkout-form").submit();
			return false;
		});
		$("#DisplayDays").change(function(){
			$("[id^=forum_days_]").submit();
		});
		
		$name_id = "contact_name";	
		$("#"+$name_id).focus(function(){
			if($("#"+$name_id).attr("value") == "Name")
				{$("#"+$name_id).attr("value", "");}
		});
		
		$("#"+$name_id).blur(function(){
			if($("#"+$name_id).attr("value") == "")
				{$("#"+$name_id).attr("value", "Name");}
		});
		
		$subject_id = "contact_subject";	
		$("#"+$subject_id).focus(function(){
			if($("#"+$subject_id).attr("value") == "Subject")
				{$("#"+$subject_id).attr("value", "");}
		});
		
		$("#"+$subject_id).blur(function(){
			if($("#"+$subject_id).attr("value") == "")
				{$("#"+$subject_id).attr("value", "Subject");}
		});
		
		$email_id = "contact_email";	
		$("#"+$email_id).focus(function(){
			if($("#"+$email_id).attr("value") == "Email Address")
				{$("#"+$email_id).attr("value", "");}
		});
		
		$("#"+$email_id).blur(function(){
			if($("#"+$email_id).attr("value") == "")
				{$("#"+$email_id).attr("value", "Email Address");}
		});
				
		$message_id = "contact_message";	
		$("#"+$message_id).focus(function(){
			if($("#"+$message_id).attr("value") == "Your Message")
				{$("#"+$message_id).attr("value", "");}
		});
		
		$("#"+$message_id).blur(function(){
			if($("#"+$message_id).attr("value") == "")
				{$("#"+$message_id).attr("value", "Your Message");}
		});
		
	});