// JavaScript Document

$(document).ready(function(){
		
	// we are using inline javascript to hide all these elements for better results	
	//hide the message element on load
	//$('.product_popup_window').hide();
	//$('#info_name_message').hide();
	//$('.blackout').hide();
	//$('.product_edit').hide();
		//utility bar located on the top of the webpage animate and hide feature
		
	//setting the body to the center of the screen
	//screenWidth = $(document).width();
	screenHeight = $(document).height();
	
	//xPoint = (screenWidth - 600)/2;
	yPoint = (screenHeight - 400)/2;

	$("#admin_body_wrapper").css({position:'relative',top:yPoint,width:'600px', height:'400px'});
	
	//xPoint1 = (screenWidth - 800)/2;
	
	//$("#admin_workspace_wrapper").css({left:xPoint1});
	
		
	//crete an element to contain white background when the bubble appears disabling other interactions
	$('<div></div>')
	.attr('id','white_board')
	.addClass('whitelight')
	.appendTo('body')
	.hide();
	
	//crete an element to contain black background when the bubble appears disabling other interactions
	$('<div></div>')
	.attr('id','top_board')
	.addClass('blackout')
	.appendTo('body')
	.hide();
	
	//One more:--crete an element to contain black background when the bubble appears disabling other interactions
	$('<div></div>')
	.attr('id','shadow')
	.addClass('blackout')
	.appendTo('body')
	.hide();
	
	
	$('.log_me_in').click(function(){
	$(".utility_find_store").hide();
	if(($(this).next()).is(':visible'))
	{
		$(this).next()
		.css({'width':'130px','height':'180px','opacity':'100'})
		.animate({'width':'0px','height':'0px','opacity':'0'},'slow')
		.hide();
	}
	else
	{
		$(this).next()
		.show()
		.css({'width':'0px','height':'0px','opacity':'0'})
		.animate({'width':'220px','height':'180px','opacity':'100'},'slow');
		
	}
	});
	
	$('.find_a_store').click(function(){
	$(".utility_login").hide();
	if(($(this).next()).is(':visible'))
	{
		$(this).next()
		.css({'width':'130px','height':'180px','opacity':'100'})
		.animate({'width':'0px','height':'0px','opacity':'0'},'slow')
		.hide();
	}
	else
	{
		$(this).next()
		.show()
		.css({'width':'0px','height':'0px','opacity':'0'})
		.animate({'width':'220px','height':'180px','opacity':'100'},'slow');
		
	}
	});
	
	
	
	// this script is for the category selection boxes on the top of the shopping cart
	$("#select_chocolate").hover(
		function(){
			$("#maincheck1").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck1").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
	
	$("#select_cookies").hover(
		function(){
			$("#maincheck2").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck2").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
	
	$("#select_coffee").hover(
		function(){
			$("#maincheck3").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck3").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
	
	$("#select_sweetie").hover(
		function(){
			$("#maincheck4").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck4").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
	
	$("#select_wildpack").hover(
		function(){
			$("#maincheck5").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck5").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
	
	$("#select_seasonal").hover(
		function(){
			$("#maincheck6").attr("src","images/shoppingCart/category_square_checked.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square.jpg");},
		function(){
			$("#maincheck6").attr("src","images/shoppingCart/category_square.jpg");
			$("#maincheck").attr("src","images/shoppingCart/category_square_checked.jpg");}
	);
						   
						   
	// this script is to erase the input box content on focus 
	$("#username_field").focus(function(){if($(this).val() == 'enter the username'){$(this).val('');};});   
	$("#password_field").focus(function(){if($(this).val() == 'enter the password'){$(this).val('');};});
						   
	//animate the product_added box
	//$("#product_added").animate(width:'50%',height:'50%','slow');
	
	//close the product_added popup
	$(".close_product_added").click(
		function(){
			$("#product_added").hide();
			$('.blackout').hide();
			//reveal scrollbars!
			$('body').css('overflow-y', 'scroll');
		}
	);
	
	//close the whproduct_added popup
	$(".close_whproduct_added").click(
		function(){
			$("#whproduct_added").hide();
			$('.blackout').hide();
			//reveal scrollbars!
			$('body').css('overflow-y', 'scroll');
		}
	);
	
	//close the product_edit popup
	$(".close_product_edit").click(
		function(){
			$(".product_edit").hide();
			$('.blackout').hide();
			//reveal scrollbars!
			$('body').css('overflow-y', 'scroll');
		}
	);
	
	//close the product_popup
	$(".close_product_popup").click(
		function(){
			$(".product_popup_window").hide();
			$('.blackout').hide();
			//reveal scrollbars!
			$('body').css('overflow-y', 'scroll');
		}
	);
	
	$(".close_me").click(
		function(){
			$(".product_popup_window").hide();
			$('.blackout').hide();
			//reveal scrollbars!
			$('body').css('overflow-y', 'scroll');
		}
	);
	
	//get element co-ordinates
	$('.info_name').click(function () {
  		var offset = $(this).offset();
		//position for message
		info_top = offset.top;
		info_left = offset.left + 20;
		$('#info_name_message').css({position:'absolute', left:info_left, top:info_top,'z-index':4});
		$('#info_name_message').toggle();
	});
	
	
	//script for edit options: on hover to delete image make background red and on hover to edit image make background blue
	$(".red_back").hover(function(){
	$(this).closest(".black_tag").css("background-color","#CE1321");
	},function(){
	$(this).closest(".black_tag").css("background-color","#4D3F26");
	});
	
	$(".blue_back").hover(function(){
	$(this).closest(".black_tag").css("background-color","#214E98");
	},function(){
	$(this).closest(".black_tag").css("background-color","#4D3F26");
	});
	
});
