var mouse_is_inside = false;
var interval_1 = '';
var interval_2 = '';
var interval_3 = '';
$(document).ready(function() {
	current_and_future_draggable();
	function current_and_future_draggable() {
		$("#drag_and_drop .right div").multidraggable({ revert: true, revertDuration: 200, helper: 'clone', opacity: 0.5, zIndex: 0, distance: 5, stop: function(event, ui) {
				if ($(".dragged_to").length > 0) {
					var old_html = $(".dragged_to p").html();
					var new_html_raw = $(this).attr("suspect").split(":");
					new_html = new_html_raw[0];
					var old_title = $(".dragged_to p").attr("dragged");
					var new_title = new_html_raw[1];
					var victim_id = $(".dragged_to p").attr("id");
					if (old_title.indexOf("{"+new_title+"}") == -1) {
						var page_name = $(location).attr('href').split("/").pop();
						$.ajax({
							async: true,
							type: "POST",
							url: "./"+page_name,
							data: "add_suspect=true&suspect_id="+new_title+"&victim_id="+victim_id,
							success: function(msg){
								if (old_html == "&nbsp;") {
									$(".dragged_to p").html("<span title=\"Remove?\" suspect=\""+new_title+"\">"+new_html+"</span>");
									$(".dragged_to p").attr("dragged", "{"+new_title+"}");
								} else {
									$(".dragged_to p").html(old_html+"<span title=\"Remove?\" suspect=\""+new_title+"\">"+new_html+"</span>");
									$(".dragged_to p").attr("dragged", old_title+"{"+new_title+"}");
								}
								var clean_this = $(".dragged_to p").html();
								var cleaned = clean_this.replace(/(\r\n|\n|\r|\s{2,})/gm, "");
								$(".dragged_to p").html(cleaned);
							}
						});
					}
					var page_name = $(location).attr('href').split("/").pop();
					$.ajax({
						async: false,
						type: "POST",
						url: "./"+page_name,
						data: "reorder_suspects=true",
						success: function(msg){
							var prefix = "";
							var output = "";
							var pieces = msg.split(":");
							if ($("#drag_and_drop .right div.disabled").length > 0) {
								var disabled_html = $("#drag_and_drop .right div.disabled").html();
								prefix = "<div suspect=\":\" title=\"Add one\" class=\"disabled\">"+disabled_html+"</div>";	
							}
							output += prefix;
							for (var i = 0; i < pieces.length; i++) {
								var cleaned_piece = pieces[i].replace(/(}|{)/gm, "");
								var pieces_2 = cleaned_piece.split(",");
								output += "<div suspect=\""+pieces_2[0]+":"+pieces_2[1]+"\" title=\"Drag me over, either on my own or CTRL+Click me and drag more of us!\">"+pieces_2[0]+"</div>";
							}
							$("#drag_and_drop .right").html(output);
							current_and_future_draggable();
						}
					});
				}
				$("#drag_and_drop .left div").css("cursor", "default");
				$("#drag_and_drop .right div").css("background", "#ffcccc");
				$("#drag_and_drop .right div").removeClass("ui-multidraggable");
			}
		});
		$(".disabled").multidraggable("destroy");
	}
	$("#drag_and_drop .left div").live("mouseover", function() {
			if ($(".ui-draggable-dragging").length > 0) {
				$(this).css("cursor", "move");
			}
			$(this).addClass("dragged_to");
			$(this).css("border", "1px solid #ff0000");
		}
	);	
	$("#drag_and_drop .left div").live("mouseout", function() {
			$(this).removeClass("dragged_to");
			$(this).css("border", "1px solid #666666");
		}
	);
	$("#drag_and_drop .right div").live("mousedown", function() {
			$(this).css("background-color", "#ff3333");	
		}
	);
	$("#drag_and_drop .right div").live("mouseup", function() {
			if (!$(this).hasClass('ui-multidraggable')) {
				$(this).css("background", "#ffcccc");
			}
		}
	);
	$("#drag_and_drop .left div p span").live('click', function() {
			var handle = $(this);
			var remove_this = handle.attr("suspect");
			var old_title = handle.parent().attr("dragged");
			var new_title = old_title.replace("{"+remove_this+"}", "");
			var victim_id = handle.parent().attr("id");
			var page_name = $(location).attr('href').split("/").pop();
			$.ajax({
				async: false,
				type: "POST",
				url: "./"+page_name,
				data: "rem_suspect=true&suspect_id="+remove_this+"&victim_id="+victim_id,
				success: function(msg){
					handle.parent().attr("dragged", new_title);
					handle.remove();
					if (msg != "no_reorder") {
						var prefix = "";
						var output = "";
						var pieces = msg.split(":");
						if ($("#drag_and_drop .right div.disabled").length > 0) {
							var disabled_html = $("#drag_and_drop .right div.disabled").html();
							prefix = "<div suspect=\":\" title=\"Add a category\" class=\"disabled\">"+disabled_html+"</div>";	
						}
						output += prefix;
						for (var i = 0; i < pieces.length; i++) {
							var cleaned_piece = pieces[i].replace(/(}|{)/gm, "");
							var pieces_2 = cleaned_piece.split(",");
							output += "<div suspect=\""+pieces_2[0]+":"+pieces_2[1]+"\" title=\"Drag me over, either on my own or CTRL+Click me and drag more of us!\">"+pieces_2[0]+"</div>";
						}
						$("#drag_and_drop .right").html(output);
						current_and_future_draggable();
					}
				}
			});
		}
	);
	$("#drag_and_drop .left div a").live('click', function() {
			var handle = $(this);
			var victim_id = handle.attr('victim');
			var page_name = $(location).attr('href').split("/").pop();
			$("#preview").css('display', 'none');
			$.ajax({
				async: false,
				type: "POST",
				url: "./"+page_name,
				data: "get_victim="+victim_id,
				success: function(msg){
					$("#preview").html("<div title=\"Done?\"></div>"+msg);
					$("#preview").fadeIn('slow');
				}
			});
		}
	);
	$("#drag_and_drop #preview div").live('click', function() {
		$(this).parent().css('display', 'none');	
		}
	);
	$("#drag_and_drop .left div div").live('click', function() {
			var handle = $(this);
			var victim_id = handle.prev().attr("id");
			var page_name = $(location).attr('href').split("/").pop();
			var status = handle.attr('status');
			$.ajax({
				async: false,
				type: "POST",
				url: "./"+page_name,
				data: "status="+status+"&victim_id="+victim_id,
				success: function(msg){
					handle.parent().fadeOut('slow', function() {
						handle.parent().remove();										 
					});
				}
			});
		}
	);
	$("#show_done").click(function(){
			var page_name = $(location).attr('href').split("/").pop();
			window.location = page_name+"?show_done=true";
		}
	);
	$("#hide_done").click(function(){
			var page_name = $(location).attr('href').split("/").pop().split("?")[0];
			window.location = page_name;
		}
	);
	$("#drag_and_drop .right div.disabled form input:submit").live('click', function(event) {
			event.preventDefault();
			var suspect = $(this).prev().val();
			var page_name = $(location).attr('href').split("/").pop();
			if (suspect != "") {
				$.ajax({
					async: false,
					type: "POST",
					url: "./"+page_name,
					data: "add=true&suspect="+suspect,
					success: function(msg){
						var prefix = "";
						var output = "";
						var pieces = msg.split(":");
						if ($("#drag_and_drop .right div.disabled").length > 0) {
							var disabled_html = $("#drag_and_drop .right div.disabled").html();
							prefix = "<div suspect=\":\" title=\"Add a category\" class=\"disabled\">"+disabled_html+"</div>";	
						}
						output += prefix;
						for (var i = 0; i < pieces.length; i++) {
							var cleaned_piece = pieces[i].replace(/(}|{)/gm, "");
							var pieces_2 = cleaned_piece.split(",");
							output += "<div suspect=\""+pieces_2[0]+":"+pieces_2[1]+"\" title=\"Drag me over, either on my own or CTRL+Click me and drag more of us!\">"+pieces_2[0]+"</div>";
						}
						$("#drag_and_drop .right").html(output);
						current_and_future_draggable();
					}
				});
			}
		}
	);
	
	$("#drag_and_drop .left div.disabled form input:submit").live('click', function(event) {
		event.preventDefault();
		var name = $(this).parent().children('input[type="text"]').val();
		var is = '';
		$(this).parent().children('input[type="checkbox"]:checked').each(function() {
			is = is+'{'+$(this).val()+'}:';
		});
		var page_name = $(location).attr('href').split("/").pop();
		if (name != "") {
			$.ajax({
				async: false,
				type: "POST",
				url: "./"+page_name,
				data: "filter=true&name="+name+"&is="+is,
				success: function(msg){
					var output = "";
					var pieces = msg.split(":");
					$("#drag_and_drop .left div:gt(0)").remove();
					for (var i = 0; i < pieces.length; i++) {
						var pieces_2 = pieces[i].split(",");
						pieces_2[0] = pieces_2[0].replace(/(}|{)/gm, "");
						pieces_2[1] = pieces_2[1].replace(/(}|{)/gm, "");
						pieces_2[2] = pieces_2[2].replace(/(}|{)/gm, "");
						output += "<div>";
						output += "<a href=\"javascript:void(0);\" victim=\""+pieces_2[0]+"\">"+pieces_2[1]+"</a> ";
						var dragged = '';
						if (pieces_2[2] != '') {
							var pieces_3 = pieces_2[2].split('#');
							for (var i2 = 0; i2 < pieces_3.length; i2++) {
								var pieces_4 = pieces_3[i2].split('@');
								dragged += "{"+pieces_4[0]+"}";
							}
						}
						output += "<p id=\""+pieces_2[0]+"\" dragged=\""+dragged+"\">";
						if (pieces_2[2] != '') {
							var pieces_3 = pieces_2[2].split('#');
							for (var i2 = 0; i2 < pieces_3.length; i2++) {
								var pieces_4 = pieces_3[i2].split('@');
								output += "<span title=\"Remove?\" suspect=\""+pieces_4[0]+"\">";
								output += pieces_4[1];
								output += "</span>";
							}
						}
						output += "</p>";
						output += "<div title=\"Done?\" status=\"categorized\"></div>";
						output += "</div>";
					}
					$("#drag_and_drop .left").append(output);
				}
			});
		}
	});
	
	function putSubNavsCorrect(the_parent) {
		var parent_width = the_parent.width();
		var margin_right = "-"+parent_width - the_parent.next("li").css("width").replace("px", "")+"px";
		var margin_left = "-"+(parent_width + 1)+"px";
		the_parent.next("li").css("margin-right", margin_right);
		the_parent.next("li").css("margin-left", margin_left);
		the_parent.next("li").css("margin-top", the_parent.height());
	}
	$("#nav li.parent").mouseover(function() {
		putSubNavsCorrect($(this));
		$(this).next("li").css("display", "list-item");	
		$(this).next("li").mouseover(function() {
			$(this).css("display", "list-item");									  
		});
		$(this).next("li").mouseout(function() {
			$(this).css("display", "none");									  
		});
	});
	$("#nav li.parent").mouseout(function() {
		putSubNavsCorrect($(this));
		$(this).next("li").css("display", "none");						  
	});
	if ($("#main").length > 0) {
		$("#main").css("min-height", "0");
	}
	$("#tiles div").click(function(){
			var go_to = $(this).children("h3").children("a").attr("href");
			window.location = go_to;
		}
	);
	$("#categories div, #products div").live('click', function() {
			var go_to = $(this).children("h2").children("a").attr("href");
			window.location = go_to;
		}
	);
	$('#header form input:first').mousedown(function() {
		if ($(this).attr('value') == 'Search me baby!') {
			$(this).attr('value', '');
			$(this).css('color', '#000000');
		}
	});
	$('#header form input:first').next('input').mouseup(function() {
		if ($('#header form input:first').attr('value') == 'Search me baby!') {
			$('#header form input:first').attr('value', '');
		}
	});
	$('#header form input:first').keyup(function(e) {
		var handle = $(this);
		handle.parent().children('div:first').css('display', 'block');
		var keep_html = handle.parent().children('div:first').children('a:first').html();
  		var sfor = handle.attr('value');
		handle.parent().children('div:first').children('a').css('display', 'none');
		handle.parent().children('div:first').children('a:first').css('display', 'block');
		if (sfor.length > 2) {
			var page_name = handle.parent().attr('action');
			var to_root = handle.parent().attr('action').replace('search', '');
			$.ajax({
				async: false,
				type: "POST",
				url: "./"+page_name,
				data: "to_root="+to_root+"&find="+sfor,
				success: function(msg){
					if (msg != '') {
						var output = "";
						pieces = msg.split(":");
						for (var i = 0; i < pieces.length; i++) {
							var cleaned_piece = pieces[i].replace(/(}|{)/gm, "");
							var pieces_2 = cleaned_piece.split(",");
							output += "<a href=\""+pieces_2[1]+"\">"+pieces_2[0]+"</a>";
						}
						handle.parent().children('div:first').children('a:first').css('display', 'none');
						handle.parent().children('div:first').html("<a href=\"javascript:void(0);\">"+keep_html+"</a>"+output);
						handle.parent().children('div:first a:odd').addClass('odd');
					} else {
						handle.parent().children('div:first').children('a:first').css('display', 'none');
						handle.parent().children('div:first').html("<a href=\"javascript:void(0);\">"+keep_html+"</a><a href=\"./"+page_name+"?find="+sfor+"\">No results found</a>");	
					}
				}
			});
		} else if ((sfor == '') && (mouse_is_inside == false)) {
			handle.attr('value', 'Search me baby!');
			handle.css('color', '#cccccc');
			handle.blur();
			handle.parent().children('div:first').css('display', 'none');
		} else {
			handle.parent().children('div:first').css('display', 'none');	
		}
	});
	$('#header form').hover(function(){ 
		mouse_is_inside = true; 
	}, function(){ 
		mouse_is_inside = false; 
	});
	$("body").mouseup(function(){ 
		if (!mouse_is_inside) {
			$('#header form input:first').attr('value', 'Search me baby!');
			$('#header form input:first').css('color', '#cccccc');
			$('#header form input:first').blur();
			$('#header form input:first').parent().children('div:first').css('display', 'none');
		}
	});
	
	if ($('#splash>div').length > 0) {
		$('#splash').append('<div></div>');
		var i = 9;
		$("#splash>div").each(function() {
			if ($(this).index() != $("#splash>div:last").index()) {
				$('#splash>div:last').append('<div></div>');
			}
			$(this).css('z-index', i);	
			i--;
		});
		$("#splash>div:last").css('z-index', 10);
		$("#splash>div:last>div:first").addClass('current');
		interval_1 = window.setInterval( function() { switchSlides('#splash>div'); }, 6000 );
	}
	
	$('#splash>div:last>div').click(function() {
		window.clearInterval(interval_1);
		$('#splash>div:last>div.current').removeClass('current');
		$(this).addClass('current');
		var stored_index = $(this).index();
		$("#splash>div").each(function() {
			if ($(this).index() < stored_index) {
				$(this).css('display', 'none');	
			} else {
				$(this).css('display', 'block');		
			}
		});
		$('#splash>div').eq($(this).index()).fadeIn(1000, function(){
			$('#splash>div.show').removeClass('show');
			$(this).addClass('show');
		});
		interval_1 = window.setInterval( function() { switchSlides('#splash>div'); }, 6000 );
	});
	
	if ($('#spotlight>div').length > 0) {
		$('#spotlight').append('<div></div>');
		var i = 9;
		$("#spotlight>div").each(function() {
			if ($(this).index() != $("#spotlight>div:last").index()) {
				$('#spotlight>div:last').append('<div></div>');
			}
			$(this).css('z-index', i);	
			i--;
		});
		$("#spotlight>div:last").css('z-index', 10);
		$("#spotlight>div:last>div:first").addClass('current');
		interval_2 = window.setInterval( function() { switchSlides('#spotlight>div'); }, 6000 );
	}
	
	$('#spotlight>div:last>div').click(function() {
		window.clearInterval(interval_2);
		$('#spotlight>div:last>div.current').removeClass('current');
		$(this).addClass('current');
		var stored_index = $(this).index();
		$("#spotlight>div").each(function() {
			if ($(this).index() < stored_index) {
				$(this).css('display', 'none');	
			} else {
				$(this).css('display', 'block');		
			}
		});
		$('#spotlight>div').eq($(this).index()).fadeIn(1000, function(){
			$('#spotlight>div.show').removeClass('show');
			$(this).addClass('show');
		});	
		interval_2 = window.setInterval( function() { switchSlides('#spotlight>div'); }, 6000 );
	});
	
	if ($('#spotlight_2>div').length > 0) {
		$('#spotlight_2').append('<div></div>');
		var i = 9;
		$("#spotlight_2>div").each(function() {
			if ($(this).index() != $("#spotlight_2>div:last").index()) {
				$('#spotlight_2>div:last').append('<div></div>');
			}
			$(this).css('z-index', i);	
			i--;
		});
		$("#spotlight_2>div:last").css('z-index', 10);
		$("#spotlight_2>div:last>div:first").addClass('current');
		interval_2 = window.setInterval( function() { switchSlides('#spotlight_2>div'); }, 6000 );
	}
	
	$('#spotlight_2>div:last>div').click(function() {
		window.clearInterval(interval_2);
		$('#spotlight_2>div:last>div.current').removeClass('current');
		$(this).addClass('current');
		var stored_index = $(this).index();
		$("#spotlight_2>div").each(function() {
			if ($(this).index() < stored_index) {
				$(this).css('display', 'none');	
			} else {
				$(this).css('display', 'block');		
			}
		});
		$('#spotlight_2>div').eq($(this).index()).fadeIn(1000, function(){
			$('#spotlight_2>div.show').removeClass('show');
			$(this).addClass('show');
		});	
		interval_2 = window.setInterval( function() { switchSlides('#spotlight_2>div'); }, 6000 );
	});
	
	function switchSlides(element) {
		var old_src = $(element).parent().children('img').attr('src');
		$(element).parent().children('img').attr('src', old_src);
		if ($(element+'.show').length < 1) {
			$(element+':first').fadeOut(1000);
			$(element+':first').next('div').addClass('show');
			$(element+':last>div').eq($(element+'.show').index()).prev().removeClass('current');
			$(element+':last>div').eq($(element+'.show').index()).addClass('current');
		} else if ($(element).eq($(element).parent().children().length - 2).hasClass('show')) {
			$(element+':last>div:last').removeClass('current');
			$(element+':last>div:first').addClass('current');
			$(element+':first').fadeIn(1000, function(){
				$(element+':first').addClass('show');
				$(element+'.show:last').removeClass('show');
				$(element).each(function() { 
					$(this).css('display', 'block');
				});
			});
		} else {
			$(element+'.show').fadeOut(1000);
			$(element+'.show').next('div').addClass('show');
			$(element+'.show:first').removeClass('show');
			$(element+':last>div').eq($(element+'.show').index()).prev().removeClass('current');
			$(element+':last>div').eq($(element+'.show').index()).addClass('current');
		}
	}
	
	$('#cont>div.filters').prependTo('#cont');
	
	$('#cont>div.filters>div a').live('click', function(event) {
		event.preventDefault();
		var limit = $('#cont>div:first>div select[name="limit"]').children('option:selected').val();
		var price = $('#cont>div:first>div select[name="price"]').children('option:selected').val();
		var material = $('#cont>div:first>div select[name="material"]').children('option:selected').val();
		var grab = $(this).attr('href')+'?type=raw&limit='+limit+'&price='+price+'&material='+material;
		getPage(grab);
	});
	
	$('#cont>div.filters>div select[name="limit"]').live('change', function(event) {
		event.preventDefault();
		var page_name = $(location).attr('href').split("/").pop().split("?")[0];
		var limit = $(this).children('option:selected').val();
		var price = $('#cont>div:first>div select[name="price"]').children('option:selected').val();
		var material = $('#cont>div:first>div select[name="material"]').children('option:selected').val();
		var grab = page_name+'?type=raw&limit='+limit+'&price='+price+'&material='+material;
		getPage(grab);
	});
	
	$('#cont>div.filters>div select[name="price"]').live('change', function(event) {
		event.preventDefault();
		var page_name = $(location).attr('href').split("/").pop().split("?")[0];
		var limit = $('#cont>div:first>div select[name="limit"]').children('option:selected').val();
		var price = $(this).children('option:selected').val();
		var material = $('#cont>div:first>div select[name="material"]').children('option:selected').val();
		var grab = page_name+'?type=raw&limit='+limit+'&price='+price+'&material='+material;
		getPage(grab);
	});
	
	$('#cont>div.filters>div select[name="material"]').live('change', function(event) {
		event.preventDefault();
		var page_name = $(location).attr('href').split("/").pop().split("?")[0];
		var limit = $('#cont>div:first>div select[name="limit"]').children('option:selected').val();
		var price = $('#cont>div:first>div select[name="price"]').children('option:selected').val();
		var material = $(this).children('option:selected').val();
		var grab = page_name+'?type=raw&limit='+limit+'&price='+price+'&material='+material;
		getPage(grab);
	});
	
	function getPage(grab) {
		$('#cont>div.overlay').css('display', 'block');
		$.get(grab, function(data) {
			var parts = data.split('||');
			if (parts[0] != '') {
				var products_output_1 = parts[0].split(':');
				var products_output = new Array();
				for (var i = 0; i < products_output_1.length; i++) {
					var products_output_1_cleaned = products_output_1[i].replace(/(}|{)/gm, "");
					var products_output_2 = products_output_1_cleaned.split(']');
					products_output.push(i);
					products_output[i] = new Array();
					for (var i2 = 0; i2 < products_output_2.length; i2++) {
						products_output[i].push(i2);
						products_output[i][i2] = products_output_2[i2];	
					}
				}
				
				var output = '';
				for (var i = 0; i < products_output.length; i++) {
					output += '<div>';	
					
					output += '<img src="'+products_output[i][0]+'" width="'+products_output[i][1]+'" alt="'+products_output[i][2]+'" />';
					output += '<h2><a href="'+products_output[i][3]+'">'+products_output[i][2]+'</a></h2>';
					output += '<p>'+products_output[i][4]+'</p>';
					output += '<a href="'+products_output[i][5]+'basket?add='+products_output[i][6]+'&referrer='+products_output[i][7]+''+products_output[i][8]+'"><img src="'+products_output[i][9]+'add_to_basket.png" width="110" height="25" alt="Add to basket" class="button" /></a>';
					output += '<p><a href="'+products_output[i][3]+'">more info</a></p>';
	
					output += '</div>';
				}
			} else {
				output = '';	
			}
			if (output != '') {
				$('#cont>#products').html(output);
			}
			$('#cont>div:first').html(parts[1]+parts[2]+parts[3]+parts[4]);
			$('#cont>div.overlay').css('display', 'none');
		});	
	}
	
	$('#cont>span.breadcumbs').prependTo('#cont>h1:first, #cont>#details>div:first>h1:first');
	
	$('#image_set>div div').click(function() {
		$('#image_set>div div.current').removeClass('current');
		$(this).addClass('current');
		var url = $(this).css('background-image').replace('url(', '').replace(')', '').replace('"', '').replace('"', '').replace('90', '400').replace('90', '400');
		if ($(this).hasClass('qr')) {
			$(this).parent().parent().children('img:first').attr('src', url);
		} else {
			var remove = $(this).attr('thumb');
			url = url.replace(remove, '');
			$(this).parent().parent().children('img:first').attr('src', url);
		}
	});
	
	var page_name = $(location).attr('href');
	if ((page_name.split("/").pop() == '') && (page_name.indexOf('/blog/', 0) == -1)) {
		$('#help').css('margin-top', '-10px').delay(1000).animate( {marginTop: '-27px'}, 1000);
	}
	$('#help>div:last').click(function() {
		if ($(this).parent().css('margin-top') == '-27px') {
			$(this).parent().animate( {marginTop: '-10px'}, 100 );
		} else {
			$(this).parent().animate( {marginTop: '-27px'}, 100 );	
		}
	});
	
	$('#help>div:last').fadeTo(0, 0.5);
	window.clearInterval(interval_3);
	interval_3 = window.setInterval( function() { pulseTab('#help>div:last'); }, 4000 );
	
	function pulseTab(element) {
		$(element).fadeTo(1000, 1.0, function() {
			$(this).delay(1000).fadeTo(1000, 0.5);										
		});
	}
	
	$('#cont #details>ul li:odd').addClass('odd');
	
	if (($('#header>div>span').length > 0) && ($('#header>div>span').html() != '0')) {
		$('#header>div').css('height', '27px');
		$('#header>div>a:last').fadeIn(1000, function() {
			$(this).css('background-color', '#52DD5E');
		});
	}
	
	$('#cont #basket tbody tr:odd').addClass('odd');
	
	$('#currency a').animate({ opacity: 0.3 }).delay(2000).animate({ opacity: 1 }, 2000).delay(500).animate({ opacity: 0.3 }, 2000);
	
	$('#remember').change(function() {
		var handle = $(this);
		after_this = handle.parent().index() - 1;
		handle.parent().parent().children('div:gt('+after_this+')').each(function() {
			if (handle.is(':checked')) {
				$(this).fadeIn(1000);
			} else {
				$(this).fadeOut(1000);		
			}
		});
	});
	
	if (!$('#remember').is(':checked')) {
		after_this = $('#remember').parent().index() - 1;
		$('#remember').parent().parent().children('div:gt('+after_this+')').each(function() {	
			$(this).css('display', 'none');																										
		});
	}
	
	$('#same_as').change(function() {
		var handle = $(this);
		after_this = handle.parent().index() - 1;
		handle.parent().parent().children('div:gt('+after_this+'):has(input[type=text], select)').each(function() {
			if (handle.is(':checked')) {
				$(this).fadeOut(1000);
				$('input[mapto]').each(function() {
					$('input[name="'+$(this).attr('mapto')+'"]').val($(this).val());								
				});
			} else {
				$(this).fadeIn(1000);		
			}
		});
	});
	
	if ($('#same_as').is(':checked')) {
		after_this = $('#same_as').parent().index() - 1;
		$('#same_as').parent().parent().children('div:gt('+after_this+'):has(input[type=text], select)').each(function() {	
			$(this).css('display', 'none');																								
		});
	}
	
	$('#country_2').change(function() {
		var handle = $(this);
		var country = handle.val().split(':').pop();
		var page_name = $(location).attr('href').split("/").pop();
		$.ajax({
			async: false,
			type: "GET",
			url: "./"+page_name,
			data: "country_raw="+country,
			success: function(msg){
				var pieces = msg.split(':');
				$('#shipping').css('display', 'none');
				$('#total').css('display', 'none');
				$('#shipping').html(pieces[0]);
				$('input[name="handling_cart"]').val(pieces[0].split(';').pop());
				$('#total').html(pieces[1]);
				$('#shipping').fadeIn(1000);
				$('#total').fadeIn(1000);
			}
		});								
	});
	
	if ($('div.small').length > 0) {
		$('div.small').attr('position', $('div.small').position().top);
	}
	
	$(window).scroll(function(){
		if ($(window).scrollTop() >= $('div.small').attr('position')) {
			$('div.small').stop().animate({'marginTop': ($(window).scrollTop() - $('div.small').attr('position') + 10) + 'px'}, 'slow' );	
		} else {
			$('div.small').stop().animate({'marginTop':	'0'});
		}
	});
	
	$('#cont>#details>ul:last-child>li').mouseover(function() {
		var output = $(this).parent().attr('output');
		$('#'+output).css('display', 'none');
		$('#'+output).stop(true, true).fadeIn(1000);
		var top = ($(this).position().top + 7) - $('#'+output).height();
		$('#'+output).css('top', top+'px');
		$('#'+output).css('display', 'block');
		var page = $(this).parent().attr('page');
		var content = $(this).attr('content');
		var grab = page+'?content='+content
		$.get(grab, function(data) {
			$('#'+output).children('img:first').css('display', 'none');			 
			$('#'+output).html(data);			 
		});
	});
	
	$('#cont>#details>ul:last-child>li').mouseout(function() {
		var li = $(this);
		var output = $(this).parent().attr('output');
		$('#'+output).stop(true, true).delay(3000).fadeOut(1000);	
	});
	
	$('#pullin').mouseover(function() {
		$(this).stop(true, true);							
	});
	
	$('#pullin').mouseout(function() {
		$(this).stop(true, true).delay(3000).fadeOut(1000);
	});
	$('.checkout_with_paypal').click(function() {
		var page_name = $(location).attr('href').split("/").pop();									  
		if ($('#same_as').is(':checked')) {
			$('input[mapto]').each(function() {
				$('input[name="'+$(this).attr('mapto')+'"]').val($(this).val());								
			});	
		}
		$('input[mapto_2]').each(function() {
			$('input[name="'+$(this).attr('mapto_2')+'"]').val($(this).val());								
		});
		var submit_to = $(this).attr('location');
		var the_form = $(this).parents('form');
		the_form.attr('action', submit_to);
		$.post(page_name, 'proceed=true&payment=1&'+the_form.serialize(), function(data) {
			the_form.submit();					 
		});
	});
});
