/* clearTimeOut Keeps the Menu Open */
clearTimeOut = 0;
clearPricingTimeOut = 0;
// Keep the Menu Open if we're highlighting a sub-menu item
function keep_open()
	{
		clearTimeOut = 0;
		clearPricingTimeOut = 0;
		try{clearTimeout(temp_timeout)}catch(e){}
	}

// Begin the closing procedure with a countdown
function close_menu(id)
	{
		clearTimeOut = 1;
		temp_timeout = setTimeout("close_menu_final("+id+");", 250);					
	}
function close_pricing()
	{
		clearPricingTimeOut = 1;
		temp_timeout = setTimeout("close_pricing_final();", 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(){jQuery(use_id).parent().children("a").removeClass("hover");}, 250);
				jQuery(use_id).slideUp({duration: 250});
			}
	}
function close_pricing_final()
	{
		// Check whether or not we've scrolled over a menu item
		if(clearPricingTimeOut == 1)
			{jQuery(".pricing-instructions").animate({left: -200});}
	}

jQuery(function(){jQuery("a[rel=lightbox]").lightBox();});
jQuery(document).ready(function()
	{
		jQuery.allowslide = 1;
		jQuery(".feature-list li a").click(function(){		
			if(jQuery.allowslide == 1){
				jQuery.allowslide = 0;	
				i = jQuery(this).parent().index();
				jQuery(".feature-list li.active").removeClass("active");
				jQuery(this).parent().addClass("active");
				jQuery(".feature-item").children("li.active").slideUp('fast').removeClass("active");
				jQuery(".feature-item").children("li").eq(i).slideDown('slow', function(){jQuery(this).addClass("active");});
				setTimeout(function(){jQuery.allowslide = 1;}, 750);
			}
			return false;
		});
		//jQuery("img").lazyload();
		jQuery(".tabs li a").click(function(){
			old_rel = jQuery(".active").attr("rel");
			rel = jQuery(this).attr("rel");
			
			jQuery(".active").removeClass("active");
			jQuery(this).addClass("active");
			
			jQuery(".tabbed-content").children("li").eq(old_rel).slideUp();
			jQuery(".tabbed-content").children("li").eq(rel).slideDown();
			return false;
		});
		jQuery("#date-from, #date-to").datepicker({dateFormat: "yy-mm-dd"});
		
		
		/*****************/
		/* PROFILE STUFF */
		
		if(document.getElementById("affiliate-summary"))
			{
				// Perform the "Magic" which is just a bit of Ajax
				jQuery.post("affiliate_admin_profile.cfm", {userid: jQuery("#affiliate-summary").attr("rel")},
					function(data) {
						 jQuery("#affiliate-summary").html("<p>Done</p>").fadeOut();
						 setTimeout(function(){jQuery("#affiliate-summary").html(data).fadeIn();}, 1500);
				});
			}
			
		
		jQuery("#platform-tabs li a").click(function(){
			tab_id = jQuery(this).attr("rel");
			jQuery(".selected").removeClass("selected");
			jQuery(this).addClass("selected");
			jQuery(".theme-table tbody").each(function(){
				if("#"+jQuery(this).attr("id") !== tab_id)
					{jQuery(this).fadeOut({duration: 299});}
			});
			setTimeout(function(){jQuery(tab_id).fadeIn();}, 300);
			return false;
		});
		jQuery("a[id^='close-announcement-']").click(function(){
			
			use_id = jQuery(this).attr("id").replace("close-announcement-", "");
			post_page = "hide_announcement.cfm";
			jQuery.get(post_page, {menuId: use_id}, 
				function(data) {jQuery(".profile-info-message").fadeOut({duration: 750});}
			);
			return false;
		});
		jQuery("a[id^='theme-upgrade-']").click(function(){
			upgrade_theme = confirm("Are you sure you want to upgrade to a Dev License for 50? \n\n This enables you to download the PSD and Fireworks files for your theme.");
			if(upgrade_theme)
				{return true;}
			else
				{return false;}				
		});
		
		/**************/
		/* MENU STUFF */
		jQuery.open_menu = 0;
		jQuery("a[id^='main-menu-item-']").mouseover(function(){
			// Start the timeout to keep the menu open
			//jQuery(this).addClass("hover")
			keep_open()
			// Create the id to ref the submenu
			sub_menu_id = jQuery(this).attr("id").replace("main-menu-item-", "");
			id = "sub-menu-"+sub_menu_id;
			new_sub_menu = "#"+id;
			
			if(jQuery.open_menu !== new_sub_menu)
				{jQuery(".sub_menu").slideUp("fast");}
		
			// fade in the submenu
			jQuery(new_sub_menu).slideDown({duration: 250});
			jQuery.open_menu = new_sub_menu;
		});
		jQuery("[id^='sub-menu-']").mouseover(function(){
			// Start the timeout to keep the menu open
			keep_open()														
		});
		jQuery("[id^='sub-menu-']").mouseout(function(){
			// Create the id to ref the submenu
			sub_menu_id = jQuery(this).attr("id").replace("sub-menu-", "");
			// Start the cloding process
			close_menu(sub_menu_id);				
		});
		jQuery("a[id^='main-menu-item-']").mouseout(function(){
			// Create the id to ref the submenu
			sub_menu_id = jQuery(this).attr("id").replace("main-menu-item-", "");
			// Start the cloding process
			close_menu(sub_menu_id);								
		});
		jQuery("#header-login-form input").focus(function(){
			keep_open();
		});
		/***************/
		/* INDEX STUFF */
		jQuery.selected_slide = 1;
		jQuery.selected_tab = 1;
		max_slides= jQuery("#client-quote-count").html(); 
		if(document.getElementById("client-quotes")) {
			setInterval(
				function()
					{
						current_id = "#quote-"+jQuery.selected_slide;
						jQuery.selected_slide++
						if(max_slides == jQuery.selected_slide)
							{jQuery.selected_slide = 1}
						new_id = "#quote-"+jQuery.selected_slide;
						jQuery(current_id).fadeOut({duration: 750});
						setTimeout(function(){jQuery(new_id).fadeIn({duration: 750});}, 800);						
					}
				,4000
			);
		};
		frame_left = 0;
		frame_no = 1;
		max_clicks = 3;
		jQuery("a[id^='theme-right-href-']").click(function(){
			move_by = 250;
			//Choose Frame Number
			new_frame_no = jQuery(this).attr("id").replace("theme-right-href-", "");
			
			//Change dot
			jQuery(".dot-selected").removeClass("dot-selected");			
			dot_id = "#theme-right-href-"+new_frame_no;
			jQuery(dot_id).addClass("dot-selected");

			//Slide me!			
			new_top = -(new_frame_no*move_by)+(move_by);
			new_top_attr = new_top+"px";
			jQuery("#theme-right-slider").animate({top: new_top_attr}, 350);

			
			return false;
		});
		
		frame_left = 0;
		frame_no = 1;
		max_clicks = jQuery("#three-col-theme-slider ul").children().size(); 
		jQuery("a[id^='index-dot-']").click(function(){
			move_by = 704;
			//Choose Frame Number
			new_frame_no = jQuery(this).attr("id").replace("index-dot-", "");
			
			//Change dot
			jQuery(".dot-selected").removeClass("dot-selected");			
			dot_id = "#index-dot-"+new_frame_no;
			jQuery(dot_id).addClass("dot-selected");

			//Slide me!			
			new_left = -(new_frame_no*move_by)+(move_by);
			new_left_attr = new_left+"px";
			jQuery("#three-col-theme-slider").animate({left: new_left_attr}, 350);

			
			return false;
		});
		
		/********************/
		/* THEME SHOP STUFF */
		frame_left = 0;
		frame_no = 0;
		start_middle = 0;
		move_by = jQuery("#screenshot-container ul").width();
		max_clicks = 3; 
		
		jQuery("#theme-cat-details-href").click(function(){
			div = jQuery("#theme-cat-details");
			if(div.hasClass("no_display"))
				{div.fadeIn().removeClass("no_display");}
			else 
				{div.fadeOut().addClass("no_display");}
			return false;
		})
		
		jQuery("#screenshot-container ul").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; 
		
		jQuery(".screenshot-container, .laptop-element .next-arrow").click(function()
			{
				new_frame = (frame_no+1);
				new_left = -(new_frame*655)
				maxframe = jQuery(".screenshot-container li").children("a").size();
				if(maxframe == 1) {return false;}
				else {
					if(new_frame == maxframe){
						new_frame = 0;
						new_left = 0;
					} 
					jQuery(".screenshot-container li").animate({"left": new_left}, 500);
					jQuery(".screenshot-container li").children("a").eq(frame_no).animate({"opacity": 0}, 500);
					jQuery(".screenshot-container li").children("a").eq(new_frame).animate({"opacity": 0}, 0);
					jQuery(".screenshot-container li").children("a").eq(new_frame).animate({"opacity": 1}, 500);
					frame_no = new_frame;
				}
				return false;
			});	
		
		
		jQuery(".laptop-element .prev-arrow").click(function()
			{
				new_frame = (frame_no-1);				
				new_left = (jQuery(".screenshot-container li").position().left+655)
				maxframe = jQuery(".screenshot-container li").children("a").size();
				if(new_frame <= 0){
					new_frame = 0;
					new_left = 0;
				}
				jQuery(".screenshot-container li").animate({"left": new_left}, 500);
				jQuery(".screenshot-container li").children("a").eq(frame_no).animate({"opacity": 0}, 500);
				jQuery(".screenshot-container li").children("a").eq(new_frame).animate({"opacity": 0}, 0);
				jQuery(".screenshot-container li").children("a").eq(new_frame).animate({"opacity": 1}, 500);
				frame_no = new_frame;
				return false;
			});	
		
		
		jQuery(".jquery").click(function(){
			jQuery("html, body").animate({scrollTop: 0}, 1000);
			jQuery(".site-overlay-container").fadeIn();
			return false;
		});
		
		jQuery(".banner-header .close").click(function(){
			if(!jQuery(this).hasClass("free")){
				jQuery(".site-overlay-container").fadeOut().removeClass("display_block");
				return false;
			}
		});
		
		/******************/
		/* VINTAGE SLIDER */
		vintageslide = 1
		jQuery(".slider-controls .previous-btn").click(function(){
			if(vintageslide == 1){
				vintageslide = 0;
					
				moveby = 480;
				element = ".home-page-scroller";
				maxleft = (jQuery(element).children("li").size()*230);
				
				currentleft = -(jQuery(element).position().left);
				newleft = ((currentleft/1)-moveby);
				// Check which direction we're moving in
				if(newleft <= 0) {
					jQuery(element).animate({left: 10}, {duration: 100}).animate({left: 0}, {duration: 650});
				} else {
					jQuery(element).animate({left: -newleft}, {duration: 650});
				}			
				setTimeout(function(){vintageslide = 1}, 650);
			};				
			return false;
		});	
		jQuery(".slider-controls .next-btn").click(function(){
			if(vintageslide == 1){
				vintageslide = 0;
				moveby = 480;
				element = ".home-page-scroller";
				maxleft = (jQuery(element).children("li").size()*230);
				
				currentleft = -(jQuery(element).position().left);
				newleft = ((currentleft/1)+moveby);
				
				// Check which direction we're moving in
	
				if(newleft > 1150) {
					jQuery(element).animate({left: -(currentleft+10)}, {duration: 100}).animate({left: -(currentleft)}, {duration: 650});
				} else {
					jQuery(element).animate({left: -newleft}, {duration: 650});
				}	
				setTimeout(function(){vintageslide = 1}, 650);
			};				
			return false;
		});
		
		jQuery("a[id^='theme-image-href-'], a[id^='theme-image-href-2-']").click(function(){
			//Choose Frame Number
			new_frame_no = jQuery(this).attr("id").replace("theme-image-href-2-", "");
			new_frame_no = new_frame_no.toString().replace("theme-image-href-", "");
			
			//Change dot
			jQuery(".dot-selected").removeClass("dot-selected");			
			dot_id = "#theme-image-href-"+new_frame_no;
			dot_id_2 = "#theme-image-href-2-"+new_frame_no;
			jQuery(dot_id+", "+dot_id_2).addClass("dot-selected");

			//Slide me!			
			new_left = -(new_frame_no*move_by)+(move_by);
			new_left_attr = new_left+"px";
			jQuery("#screenshot-slider").animate({left: new_left_attr}, 350);

			
			return false;
		});
		
		jQuery("#expand-product-window").click(function(){
			if(jQuery(this).html() == "Expand Screenshot Window")
				{
					new_height = jQuery("#image_container div img").height();
					if(new_height > 600) 
						{new_height = 600;}
					jQuery(".screenshot-container").animate({height: new_height}, 150);
					jQuery(".prev-screenshot, .next-screenshot").animate({top: ((new_height/2)-12)}, 400);
					jQuery(this).html("Contract Screenshot Window");
				}
			else
				{
					jQuery(".screenshot-container").animate({height: 460}, 150);
					jQuery(".prev-screenshot, .next-screenshot").animate({top: 120}, 400);
					jQuery(this).html("Expand Screenshot Window");
				}
			return false;
		});
		
		jQuery(".view-all-features").click(function(){
				if(jQuery(this).html() == "View All Features")
					{
						jQuery(this).html("Hide Extra Features");
						jQuery("[id^=hidden-features-]").slideDown("fast");
					}
				else
					{
						jQuery(this).html("View All Features");
						jQuery("[id^=hidden-features-]").slideUp("fast");
					}				
				return false;
			});

		jQuery("a[id^='purchase-options-href-']").click(function(){
			id = jQuery(this).attr("id").replace("href-", "div-");
			use_id = "#"+id;
			if(jQuery(this).html() !== "Cancel")
				{
					jQuery(use_id).fadeIn("fast");
					jQuery(this).html("Cancel");
				}
			else
				{
					jQuery(use_id).fadeOut("fast");
					jQuery(this).html("Purchase");
				}
			return false;
		});
		
		jQuery("#pricing-grid li a").mouseover(function(){
			jQuery(".pricing-instructions").animate({left: 0});
		});
		
		jQuery("#pricing-grid, #pricing-grid li a").mouseout(function(){
			close_pricing();
		});
		
		jQuery("a[id^='add-']").mouseover(function(){
			// Start the timeout to keep the menu open
			keep_open();
			useid = jQuery(this).attr("id").replace("add-", "");
			 
			price_id = "#price-desicription-"+useid;
			old_price = "#price-desicription-"+jQuery.chosen_price;
			
			jQuery(old_price).css("display", "none");
			jQuery(price_id).css("display", "block");
			 
			jQuery.chosen_price = useid;
		});
		
		/*******************/
		/* OCMX PAGE STUFF */
		
		jQuery("[id^='ocmx-feature-']").click(function(){

			if(jQuery(this).attr("id").indexOf("href") < 0)
			{
				i = jQuery(this).attr("id").replace("ocmx-feature-", "");
				slide = (i-1);
				
				jQuery(".feature-controls > .selected").removeClass("selected");
				jQuery(this).parent("").addClass("selected");
				jQuery(".selected-feature").animate({left: (-940*(i-1))});
				
				jQuery("div.feature-details > a.selected").removeClass("selected");			
				
				href_id = "#ocmx-feature-href-"+i+"-1";
				jQuery(href_id).addClass("selected");
				jQuery(href_id).attr("src", jQuery("#feature-"+i+"-1").attr("rel"));
			}
			return false;
		});
		
		jQuery("[id^='ocmx-feature-href-']").click(function(){
			i = jQuery(this).attr("id").replace("ocmx-feature-href-", "");
			img_id = i.substr(0,1);
			
			//jQuery("div.feature-details a").removeClass("selected");			
			jQuery("[id^='ocmx-feature-href-"+img_id+"']").removeClass("selected");			
			
			jQuery(this).addClass("selected");
			
			jQuery("#feature-img-"+img_id).attr("src", jQuery(this).attr("rel"));
		});
		
		/******************/
		/* SHOWCASE STUFF */
		
		jQuery("[id^=like-showcase-]").click(function(){
			menuId = jQuery(this).attr("id").replace("like-showcase-", "");
			if(jQuery(this).parent().hasClass("mod-like-active"))
				{
					jQuery(this).parent().attr("class", "mod-like");
					like = 0;
				}
			else
				{
					jQuery(this).parent().attr("class", "mod-like-active");
					like = 1;
				}
			// Compile the request location
			post_page = "like_showcase.cfm";
			jQuery.post(post_page, {menuId: menuId, like: like}, 
				function(data) {
					jQuery("#likes").html(data);
			});
			return false;
		});
		
		/**************/
		/* CART STUFF */
		
		jQuery("[id^=add-]").click(function(){jQuery(".feed").html("Redirecting to the Checkout Page");});
		jQuery("[id^=remove-]").click(function(){jQuery(".feed").html("Removing Product");});
		
		
		jQuery("#register").click(function(){
			use_id = "#"+jQuery(this).attr("id").replace("href", "div");
			if(!(jQuery(this).hasClass("selected")))
				{
					jQuery("#use_register_checkout").removeAttr("disabled");
					jQuery("#use_login_checkout").attr("disabled", "disabled");
					
					jQuery("#login-checkout-href").removeClass("selected");
					jQuery("#register-checkout-href").addClass("selected");
					jQuery("#register-checkout-div").slideDown();
					jQuery("#login-checkout-div").slideUp();
				}
			return false;
		});
		
		jQuery("#login-checkout-href").click(function(){
			use_id = "#"+jQuery(this).attr("id").replace("href", "div");
			if(!(jQuery(this).hasClass("selected")))
				{
					jQuery("#use_login_checkout").removeAttr("disabled");
					jQuery("#use_register_checkout").attr("disabled", "disabled");
					
					jQuery("#register-checkout-href").removeClass("selected");
					jQuery("#login-checkout-href").addClass("selected");
					jQuery("#login-checkout-div").slideDown();
					jQuery("#register-checkout-div").slideUp();
				}
			return false;
		});
		jQuery("#change-pass").click(function(){
			if(jQuery("#password-fields").hasClass("no_display"))
				{
					jQuery("#password-fields").slideDown().removeClass("no_display");
					jQuery(this).html("Cancel");
				}
			else
				{
					jQuery("#password-fields").slideUp().addClass("no_display");
					jQuery(this).html("Change Your Password");
				}
			return false;
		});
		jQuery("[id^=checkout-theme-]").click(function(){
			my_free_themes = "";
			my_free_themes_count = jQuery("#free_theme_count").attr("value");
			max_free_themes = jQuery("#max_free_themes").attr("value");

			use_theme = jQuery(this).attr("id").replace("checkout-theme-", "");
			
			
			
			if((max_free_themes > my_free_themes_count && max_free_themes !== my_free_themes_count) && !(jQuery(this).hasClass("active")))
				{
					jQuery(this).addClass("selected");
				}
			else if(!(jQuery(this).hasClass("selected")))
				{
					str_len = (jQuery("#free_themes").attr("value").length-6);
					if(str_len > 0)
						{
							use_id = jQuery("#free_themes").attr("value").substr(str_len , 6);
							use_id = "#checkout-theme-"+use_id;
							jQuery(use_id).removeClass("selected");
						}
					else
						{jQuery(".selected").removeClass("selected");}
					jQuery(this).addClass("selected");
				}
			else
				{jQuery(this).removeClass("selected");}
				
			my_free_themes_count = 0;
			jQuery(".selected").each(function(){
				use_theme_id = jQuery(this).attr("id").replace("checkout-theme-", "");
				
				if(my_free_themes == "")
					{my_free_themes = use_theme_id;}
				else
					{my_free_themes += ","+use_theme_id;}
					
				if(use_theme_id !== "")
					{my_free_themes_count++;}
			});
			
			jQuery("#free_theme_count").attr("value", my_free_themes_count);
			jQuery("#free_themes").attr("value", my_free_themes);

			//	jQuery("#free_theme_count_html").html((max_free_themes-(my_free_themes_count/1)));
			return false;
		});
		
		jQuery("#shopping-cart").click(function(){
			if(jQuery("#cart-container").css("display") == "none")
				{jQuery("#cart-container").fadeIn();}
			else
				{jQuery("#cart-container").fadeOut();}
			return false;
		});
		
		
		jQuery("#coupon").focus(function(){
			jQuery("#checkout-form").attr("action", "checkout.cfm");
		});
		
		jQuery("#coupon").blur(function(){
			jQuery("#checkout-form").attr("action", "2checkout_direct.cfm");
		});
		
		jQuery("[id^=validate-coupon]").click(function(){	
			if(jQuery("#use_login_checkout").attr("disabled") == true){
				path = "checkout.cfm?register=1";
			}else{
				path = "checkout.cfm?login=1";
			}	
			jQuery("#checkout-form").attr("action", path);
			jQuery("#checkout-form").submit();
			return false;
		});
		
		jQuery("[id^=checkout-tab-]").click(function()
			{
				if(jQuery(this).attr("id") == "checkout-tab-1")
					{
						jQuery(this).addClass("register-button-active");
						jQuery("#checkout-tab-2").removeClass("login-button-active");
						jQuery("#checkout-content-1").slideDown("fast");
						jQuery("#checkout-content-2").slideUp("fast");
					}
				else
					{
						jQuery("#checkout-tab-1").removeClass("register-button-active");
						jQuery(this).addClass("login-button-active");
						jQuery("#checkout-content-1").slideUp("fast");
						jQuery("#checkout-content-2").slideDown("fast");
					}
				return false;
			});
		/**************/
		/* BLOG STUFF */
		
		jQuery("#comment_form").submit(function(){
			// Compile the request location
			post_page = "refresh_comments.cfm";
			// Compile all the request details
			menuId = jQuery("#menuid").attr("value");
			section = jQuery("#section").attr("value");
			name = jQuery("#name").attr("value");
			email = jQuery("#email").attr("value");
			link = jQuery("#url").attr("value");
			comment = jQuery("#comment").attr("value");
			email_subscribe = jQuery("#check_subscribe").attr("checked");
			
			error = "";
			if(name == "" || name == "Name"){error += "\n Enter in your name.";}
			if(comment == ""){error += "\n Enter in a comment."}
			if(error)
				{
					alert("Please correct the following:\n"+error);
					return false;
				}
			else
				{
					// Fade out the new comment div so that we can fade it in after posting our new comment
					//jQuery(new_comments_id).fadeOut("fast");
					jQuery("#commment-post-alert").fadeIn("slow");
							
		
					// Perform the "Magic" which is just a bit of Ajax
					jQuery.post(post_page, {menuId: menuId, name: name, email: email, url: link, comment: comment, section: section, email_subscribe: email_subscribe, insert : 1}, 
						function(data) {
							if(jQuery.browser.msie)
								{location.reload();}
							else
								{jQuery("#new_comments").html(jQuery("#new_comments").html()+" "+data).fadeIn("slow");}
							jQuery("#commment-post-alert").fadeOut("fast");
							jQuery("#comment").attr("value", "");
					});
				}
			return false;
		});
	
	
		jQuery(".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;}
		});
		jQuery("#header-login-btn, #close-login").click(function()
			{	
				
				if(jQuery("#header-cart-form").attr("class") !== "no_dispaly")
					{
						jQuery(".cart-tip").fadeOut("slow");
						jQuery("#header-cart-form").slideUp("slow").addClass("no_display");
					}
				if(jQuery("#header-login-btn").html() == "Logout")
					{
						container_dim();
						jQuery("#login-menu").slideUp("fast");
					}
				else if(jQuery("#header_login_form").attr("class") == "no_display")
					{
						container_dim();
						jQuery("#header_login_form").fadeIn("slow").removeClass("no_display");						
						jQuery("#header-login-btn").html("Hide Form");
						return false;
					}				
				else
					{
						jQuery("#login-form-alert").html("");
						jQuery("#header_login_form").fadeOut("fast").addClass("no_display");
						jQuery("#header-login-btn").html("Login");
						container_lighten();
						return false;
					}
			});
		
		jQuery("#forget-me").click(function()
			{
				jQuery("#login-menu").slideUp("fast");
				post_page = "forget_me.cfm";
				jQuery("#cookie-info").remove();
				jQuery("#cart-li").remove();
				jQuery.post(post_page, {}, function(data){jQuery("#login-menu").slideDown("fast");});
				jQuery.post("fetch-cart-details.cfm?fetch=1", {},
				function(data)
					{
						jQuery("#login-menu").append(data).slideDown("fast");
						jQuery("#cart-li").slideDown("slow");
					});
				return false;
			});
		
		/*****************/
		/* DOCUMENTATION */
				
		jQuery.selected_doc_tab = 1;
		
		jQuery("#documantation-theme-selector #theme-list").change(function(){
			jQuery("#documantation-theme-selector").submit();
		});
		jQuery("[id^=documentation-href-]").click(function(){
				id = jQuery(this).attr("id").replace("documentation-href-", "");
				old_href = "#documentation-href-"+jQuery.selected_doc_tab;
				old_ul = "#documentation-ul-"+jQuery.selected_doc_tab;
				old_detail = "#details-"+jQuery.selected_doc_tab+"-1";
				old_tab = "#documentation-details-"+jQuery.selected_doc_tab;				
				new_href = "#documentation-href-"+id;			
				new_ul = "#documentation-ul-"+id;
				new_detail = "#details-1-"+id;
				new_tab = "#documentation-details-"+id;
				
				jQuery(old_href).removeClass("selected");				
				jQuery(new_href).addClass("selected");
				
				jQuery(old_detail).slideUp("fast");
				jQuery(old_tab).fadeOut("fast");
				jQuery(old_ul).slideUp("fast");
				setTimeout(function()
					{						
						jQuery(new_tab).fadeIn("fast").addClass("clearfix");
						jQuery(new_detail).fadeIn("fast");
						jQuery(new_ul).slideDown("fast");
					}, 200);
				
				old_sub_href = "#expand-href-1-"+jQuery.selected_doc_tab;
				
				jQuery.selected_doc_tab = id;
				jQuery.selected_doc_detail = "1-"+id;
				
				new_sub_href = "#expand-href-"+jQuery.selected_doc_detail;		
				
				jQuery(old_sub_href).removeClass("selected");				
				jQuery(new_sub_href).addClass("selected");		
				
				return false
			});
		
		jQuery.selected_doc_detail = "1-1";
		jQuery("a[id^=expand-href-]").click(function(){
			id = jQuery(this).attr("id").replace("expand-href-", "");
			old_doc_deet = jQuery.selected_doc_detail;
			if(id !== jQuery.selected_doc_detail)
				{
					old_sub_href = "#expand-href-"+jQuery.selected_doc_detail;
					old_tab = "#details-"+jQuery.selected_doc_detail;
					new_sub_href = "#expand-href-"+id;	
					new_tab = "#details-"+id;
					
					jQuery(old_sub_href).removeClass("selected");				
					jQuery(new_sub_href).addClass("selected");	
					
					jQuery(old_tab).fadeOut("fast");
					setTimeout(function(){jQuery(new_tab).fadeIn("fast").addClass("clearfix");}, 195);
				}
			jQuery.selected_doc_detail = id;
			return false;
		});
		
		
		jQuery("a[id^='documentation-image-href-']").click(function(){
			move_by = 322;
			//Choose Frame Number
			new_frame_no = jQuery(this).attr("id").replace("documentation-image-href-"+jQuery.selected_doc_detail+"-", "");			
			slider_id = "#documentation-slider-"+jQuery.selected_doc_detail;
			
			//Change dot
			jQuery(".dot-selected").removeClass("dot-selected");						
			jQuery(this).addClass("dot-selected");
			
			//Slide me!			
			new_left = -(new_frame_no*move_by)+(move_by);
			new_left_attr = new_left+"px";
			
			jQuery(slider_id).animate({left: new_left_attr}, 350);
			
			return false;
		});
		
		
		
		/*****************/
		/* PROFILE STUFF */
		currentthemeslide = 1;
		jQuery("#theme-list-prev").click(function(){
			moveby = 360;
			element = ".theme-slider";
			maxclicks = jQuery(element).children("li").size();
			newid = (currentthemeslide-1);
			// Check which direction we're moving in
			if(newid <= 0) {
				newid = 1;
				lefti = moveby*(maxclicks-1);
				jQuery(element).animate({left: 10}, {duration: 100}).animate({left: 0}, {duration: 250});
			} else {
				lefti = (newid-1)*moveby;
				jQuery(element).animate({left: -lefti}, {duration: 200});
			}			
			currentthemeslide = newid;		
			return false;
		});
		jQuery("#theme-list-next").click(function(){
			moveby = 360;
			element = ".theme-slider";
			maxclicks = jQuery(element).children("li").size();
			newid = ((currentthemeslide/1)+1);
			
			// Check which direction we're moving in
			if(newid >= maxclicks) {
				newid = (maxclicks-1);
				lefti = moveby*(maxclicks-2);
				jQuery(element).animate({left: -(lefti+10)}, {duration: 100}).animate({left: -(lefti)}, {duration: 250});
			} else {
				lefti = (newid-1)*moveby;
				jQuery(element).animate({left: -lefti}, {duration: 200});
			}			
			currentthemeslide = newid;		
			return false;
		});
		
		jQuery(".forum-post-title.fade").click(function(){
			
			if(!jQuery(this).hasClass("active"))
				{jQuery(this).parent().parent().next().fadeIn();}
			else
				{jQuery(this).parent().parent().next().fadeOut();}
				
			jQuery(this).toggleClass("active");
			
			return false;	
		});
		
		jQuery(".forum.actions li a").click(function(){
			element = jQuery(this).parent().parent().parent().parent().parent();
			href = jQuery(this).attr("href");
			if(href.toString().indexOf("message.cfm") == "-1")
				{
					jQuery.get(href, {}, function(){
							element.html("<td colspan=\"6\"><p>Clearing...</p></td>");
							setTimeout(function(){element.fadeOut(); element.next().fadeOut();}, 500);
						});
					return false;
				}
		});
		
		jQuery(".action-btn").click(function(){
			
			if(!jQuery(this).hasClass("active")) {
				jQuery(".actions").fadeOut();
				jQuery(".action-btn.active").removeClass("active");
				
				thisbtn = this;
				setTimeout(function(){
					jQuery(thisbtn).addClass("active");
					jQuery(thisbtn).next().fadeIn();
					}
				, 250);
			} else {
				jQuery(".actions").fadeOut();
				jQuery(this).removeClass("active");
				
			}
			return false;
		});
		
		jQuery("[id^='ping-']").click(function(){
			hrefid = jQuery(this).attr("id");
			threadid = hrefid.replace("ping-", "");
			forum = jQuery(this).attr("rel");
			jQuery.post("message-ping.cfm", {forum: forum, threadid: threadid}, function(data)
				{
					jQuery("#"+hrefid).text("Sent").fadeOut();
				});
			return false;
		});
		
		jQuery("#source_domain").keyup(function(){
			if(document.getElementById("new_theme"))
				{
					use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery(this).attr("value")+"/style.css\" />";
					use_html += "\n<!--[if lte IE 8]><link href=\""+jQuery(this).attr("value")+"/ie7-style.css\" rel=\"stylesheet\" type=\"text/css\" />";
					use_html += "\n<script src=\""+jQuery(this).attr("value")+"/js/domassistantcompressed-2.7.4.js\" type=\"text/javascript\"></script>";
					use_html += "\n<script src=\""+jQuery(this).attr("value")+"/js/ie-css3.js\" type=\"text/javascript\"></script>";
					use_html += "\n<![endif]-->";
				}
			else if(document.getElementById("colour"))
				{
					use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery(this).attr("value")+"/style.css\" />";
					use_html += "\n<!--[if lte IE 8]><link href=\""+jQuery(this).attr("value")+"/ie-style.css\" rel=\"stylesheet\" type=\"text/css\"><![endif]-->";
					use_html += "\n<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery(this).attr("value")+"/color-styles/"+jQuery("#colour").attr("value")+"/style.css\" />";
				}
			else
				{use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery(this).attr("value")+"/style.css\" />";}
			jQuery("#source_code").attr("value", use_html);
		});
		jQuery("#colour").change(function(){
			use_html = "<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery("#source_domain").attr("value")+"/style.css\" />";
			use_html += "\n<!--[if lte IE 8]><link href=\""+jQuery("#source_domain").attr("value")+"/ie-style.css\" rel=\"stylesheet\" type=\"text/css\"><![endif]-->";
			use_html += "\n<link rel=\"stylesheet\" type=\"text/css\" href=\""+jQuery("#source_domain").attr("value")+"/color-styles/"+jQuery("#colour").attr("value")+"/style.css\" />";
			jQuery("#source_code").attr("value", use_html);
		});
		old_colour = jQuery("#code_colour").attr("value");
		jQuery("#code_colour").change(function(){
			if(document.getElementById("tumblr_code"))
				{
					alert(old_colour+", "+jQuery(this).attr("value"))
					tumblr_code = jQuery("#tumblr_code").attr("value").replace(old_colour, jQuery(this).attr("value"));
					jQuery("#tumblr_code").attr("value", tumblr_code);
				}
			
			if(document.getElementById("posterous_code"))
				{
					posterous_code = jQuery("#posterous_code").attr("value").replace(old_colour, jQuery(this).attr("value"));
					jQuery("#posterous_code").attr("value", posterous_code);
				}
			old_colour = jQuery(this).attr("value");
		});
		jQuery("#tumblr_code_href").click(function(){
			jQuery("#posterous_code_href").removeClass("active");
			jQuery("#posterous_code_div").fadeOut("fast");
			
			jQuery("#tumblr_code_href").addClass("active");
			setTimeout(function(){
				jQuery("#tumblr_code_div").fadeIn("fast");
			}, 200)
			return false;
		});
		jQuery("#posterous_code_href").click(function(){
			jQuery("#tumblr_code_href").removeClass("active");
			jQuery("#tumblr_code_div").fadeOut("fast");
			
			jQuery("#posterous_code_href").addClass("active");
			setTimeout(function(){
				jQuery("#posterous_code_div").fadeIn("fast");
			}, 200)
			return false;
		});
		
		/* Hotfix Listing*/
		jQuery("[id^=hotfix-href-]").click(function()
			{
				use_id = jQuery(this).attr("id").replace("hotfix-href-", "#hotfix-details-");
				
				if(jQuery(use_id).attr("class") == "no_display")
					{jQuery(use_id).slideDown("slow").removeClass("no_display");}
				else
					{jQuery(use_id).slideUp("slow").addClass("no_display");}
				return false;
			});
		
		/* Tab Swapping */
		if(document.getElementById("profile-tab"))
			{jQuery.profiletab = jQuery("#profile-tab").html();}
		else
			{jQuery.profiletab = 1;}
		tab_id = new Array();
		old_tab_id = new Array();
		check_load_page = new Array();
		load_page = new Array();
		jQuery("[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-" + jQuery.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(jQuery(".selected > a").attr("id") !== this.id)
				{
					//Fade the Old Form Out
					jQuery(old_tab_id[id]).slideUp("fast");
					
					//Fade the New Form out, Change it's Class, and Fade it in again
					jQuery(tab_id[id]).addClass("selected_tab").slideDown("fast");
											
					//Clear the Class of the Selected Tab
					jQuery(".selected").attr("class", "")
					//Clear the Class of the New Tab						
					jQuery(this).parent().attr("class", "selected")
					
					if(document.getElementById(check_load_page[id]))
						{
							post_page = jQuery(load_page[id]).html();
							jQuery.post(post_page, {}, function(data)
							{									
								jQuery(tab_id[id]+" > div").html(data);
								jQuery(tab_id[id]+" > p").remove();
								jQuery("#"+check_load_page).attr("id", "");
								jQuery(function(){jQuery("[id^=banner-img-]").lightBox();});
							});
						}
				}
			jQuery.profiletab = id;
			return false;
		});
		
		/* Banner List */
		jQuery("[id^=show-hide-], [id^=tr-show-hide-]").live("click", function(){
				if(jQuery(this).attr("id").indexOf("tr") !== -1)
					{
						tbody = "#"+jQuery(this).attr("id").replace("tr-show-hide-", "body-");
						href_id = "#"+jQuery(this).attr("id").replace("tr-show-hide-", "show-hide-");
					}
				else
					{
						tbody = "#"+jQuery(this).attr("id").replace("show-hide-", "body-");
						href_id = "#"+jQuery(this).attr("id");
					}
					
				if(jQuery(href_id).html().indexOf("+ Expand") !== -1)
					{
						jQuery(href_id).html("- Hide");
						jQuery(tbody).fadeIn("slow");
					}
				else
					{
						jQuery(href_id).html("+ Expand");
						jQuery(tbody).fadeOut("fast");
					}
				return false;
			});
	});

jQuery(document).keyup(function(e) {
  if (e.keyCode == 27) {
		jQuery(".site-overlay-container").fadeOut().removeClass("display_block");
	}
});
