// JavaScript Document
$(document).ready(function(){ 
  	
        
	$('.remove_from_cart').live('click',function(e){
      	e.preventDefault();
      	var rowid =  $(this).attr("id").replace("remove_cart_item_","");
       	
      	var parameters = {};
      	parameters['type'] 			= 2;
        parameters['rowid'] 		= rowid;
        
        blockElement('#cart_block');
        blockElement('#cart-detail-content');
        blockElement('#cart_holder');
   		$.post(base_url + 'order/ajaxwork', parameters , function(data){
	 		$('#cart_block').html(data.html);
	 		$('#cart_holder').html(data.mini_html);
	 		$('#order-detail-content').html(data.html_cart);
	 		$('.cart_last_product').html(data.last_product);
	 		
	 		if( parseInt(data.total_items) == 0 )
	 		{
	 			$('#next_cart').remove();
	 			$('#cart_voucher').hide();
	 		}
	 		
	 		// set the items number on main navigation
	 		$( '#cart_total_product' ).html( data.total_items );
	 		
	 		unblockElement('#cart-detail-content');
	       	unblockElement('#cart_block');
	       	unblockElement('#cart_holder');
	 	},"json");
        
    });
	
	
});
	/* block functions */

	function blockObject(obj)
	{
	     obj.block
	     ({
	        message: '<div><img src="'+base_url+'application/modules/global/images/ajax-loader-big.gif"/></div>',  
	        css: {border:'0px','background-color':'transparent',position:'absolute'},
	        overlayCSS: {opacity:0.04,cursor:'pointer'}
	      });
	 }

	function unblockObject(obj)
	{
	    obj.unblock();
	}


	function blockElement(elementSelector)
	{
	     $(elementSelector).block
	     ({
	        message: '<div><img src="'+base_url+'application/modules/global/images/ajax-loader-big.gif"/></div>',  
	        css: {border:'0px','background-color':'transparent',position:'absolute'},
	        overlayCSS: {opacity:0.04,cursor:'pointer',position:'absolute'}
	      });
	 }

	function unblockElement(elementSelector)
	{
	    $(elementSelector).unblock();
	}

	function handleJSON_response(data)
	{

	    if (data.js)
	    {
	        alert(data.js);
	        eval(data.js);
	    }

	}

	function hideModal()
	{
		if(doHide)
		{
			doHide = false;
			$("#newsletterModal").css("visibility", "hidden");
			$("#newsletter").removeClass("active");
		}
	}

	function initTabs(selector)
	{
		// Hide all tabs
		$("#" + selector + " div.tab").css("display", "none");
		
		// Show the first tab
		$("#" + selector + " div.tab:eq(0)").css("display", "block");
		$("#" + selector + " ul.tabs li:eq(0)").addClass("active");
		
		$("#" + selector + " ul.tabs li a").bind("click", function(e)
		{
			e.preventDefault();
			
			var parentObject		= $(this).parent();
			var selectedTabIndex 	= $( 'ul.tabs li' ).index( parentObject );
			
			// Set all the tabs to inactive
			$("#" + selector + " ul.tabs li").removeClass("active");
			
			// Now set the correct tab to active
			$("#" + selector + " ul.tabs li:eq(" + selectedTabIndex + ")").addClass("active");
			
			// Hide all tabs
			$("#" + selector + " div.tab").css("display", "none");
			
			// Show the selected tab
			$("#" + selector + " div.tab:eq(" + selectedTabIndex + ")").css("display", "block");		
		});
	}

		
	/***
	* adjustScreen changes the height of the content area so the footer always sits at the bottom of the screen.
	*/
	function adjustScreen()
	{
		var body_id = $("body").attr("id");
		if(body_id != "home")
		{
			var header_height = 175;
			var footer_height = 60;
			var availableHeight = 0;
				
			availableHeight = getAvailableHeight();
				
			var contentHeight = availableHeight - (header_height + footer_height);
			$("#content").css("min-height", contentHeight + "px");
		}
	}

	/***
	* getAvailableHeight
	* Gets the available screen height, taking into account toolbars.
	*/
	function getAvailableHeight() 
	{
		var window_height = 0;

		if (typeof (window.innerHeight) == "number")
			window_height = window.innerHeight;
		else 
		{
			if (document.documentElement && document.documentElement.clientHeight)
				window_height = document.documentElement.clientHeight;
			else 
			{
				if (document.body && document.body.clientHeight) 
					window_height = document.body.clientHeight;
			}
		}
		
		return window_height;
	}	
