$(function(){
	//Ready
	
	//http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	
	$.ajaxSetup ({   
	        cache: false
			/*success: function(msg){
             alert( "Data Saved: " + msg );
           }*/

	    });  
	var ajax_load_icon = "<img src='/images/ajaxloader/ajax-loader_snake.gif' alt='loading...' />";  
	 
	
	$(".action").click(function(event) {
		event.preventDefault();
		$(".favPopupDiv").hide();//close any other open divs
		var itemID= $(this).attr("itemID");
		var varID= $(this).attr("varID");
		var targetDiv= $(this).attr("targetDiv");
		var div = $(this).parent().find(".favPopupDiv");
		div.css("z-index","1000")
		div.show('slow');
		var favAjaxDiv = $("#"+targetDiv);
		var loadUrl = "/myaccount/loadFavourites.asp?itemID="+itemID+"&varID="+varID; 
		favAjaxDiv.html(ajax_load_icon).load(loadUrl);
		//div.hide('slow');
		//load content
		//var favAjaxDiv = $(this).parent().find("#favAjaxDiv");
		//var favAjaxDiv = $(this).parent().find("#"+targetDiv);
		//favAjaxDiv.append(loadUrl);
		//alert(loadUrl);
		//favAjaxDiv.css("border","3px solid red").append("<br>"+targetDiv);
	});	
	
	$(".favPopupClose").click(function(event) {
		event.preventDefault();
		var div = $(this).parent();
		div.hide('slow');
	});	
	
	
	function hidePopups(){
		setTimeout(function(){
			$(".favPopupDiv").fadeOut('slow');
			}, 1500);
		
		}


	
	/*These are generated by the ajax request itself and need to be hooked up using LIVE*/
	$(".ajax_action").live('click',function(event) {
		event.preventDefault();
		var task= $(this).attr("task");
		var itemID= $(this).attr("itemID");
		var varID= $(this).attr("varID");
		var targetDiv= $(this).attr("targetDiv");
		var thisTargetDiv = $("#"+targetDiv); //$(this).parent().find("#favAjaxDiv");
		var loadUrl = "/myaccount/loadFavourites.asp?task="+task+"&itemID="+itemID+"&varID="+varID; 
		//alert(loadUrl);
		
		thisTargetDiv.html(ajax_load_icon).load(loadUrl,
			function (responseText, textStatus, XMLHttpRequest) { 
			    if (textStatus == "success") { 
					hidePopups();
					//.doTimeout();
			    } 
			    if (textStatus == "error") { 
					 thisTargetDiv.html("error!<br />"+responseText);
			    } 
			 } );
		

		
	});	
	
//end ready
});

	
