//var processOnload = false;

jQuery(function($) {	
	
	$('#shippAddrSame').click(function(){
		if($(this).attr('checked')) {
			assignValueFrom('firstName','shippAddrFirstName');
			assignValueFrom('lastName','shippAddrLastName');
			assignValueFrom('address1','shippAddrAddress1');
			assignValueFrom('postalCode','shippAddrPostalCode');
			assignValueFrom('city','shippAddrCity');
			assignValueFrom('state','shippAddrState','combo');
			assignValueFrom('phone1','shippAddrPhone1');
			
			
		}
		});
	
	$("li a[href='#']", $("div.accordion")).click(function() {	
												 
		if ( $(this).parent().children('ul').length > 0) {
			
			if ($(this).parent().children('ul').is(":visible")) {
				$(this).parent().children('ul').slideUp();
				
				if ($(this).parent().hasClass('level2')) {
					$(this).parent().removeClass('active active_arrow');
				}
				
			} else {
				$(this).parent().children('ul').slideDown();
				
				if ($(this).parent().hasClass('level2')) {
					$(this).parent().addClass('active active_arrow');
				}
			}
			
		} else {
			// do nthing ...
		}
		
		return false;
	});		
		
		
	
	$("li a", $("div.accordion2")).click(function() {
		
		if ( $(this).parent().children('ul').length > 0) {
			
			if ($(this).parent().children('ul').is(":visible")) {
				$(this).parent().children('ul').slideUp();
				$(this).removeClass('active');
				
			} else {
				$(this).parent().children('ul').slideDown();
				$(this).addClass('active');
			}
			
		} else {
			// do nthing ...
		}
		
		return false;
	});		
	
	
	
	
	$("ul.grey_tabs li").eq(0).addClass('active');
	$("ul.grey_tabs li a").eq(0).addClass('active');
	
	$("ul.grey_tabs li").click(function() {
										
		var curRel = $("a", $(this)).attr('rel');	
		
		$("div.tab_form").hide();
		$("ul.grey_tabs li").removeClass('active');
		$("ul.grey_tabs li a").removeClass('active');
		
		$("div." + curRel).show();
		$(this).addClass('active');
		$("a", $(this)).addClass('active');
		
		return false;
	});
	
	
	
	
	/*$("a.tooltip").hover(function(){ 
		$("div.tool_tip").show();
		
	},function(){
		$("div.tool_tip").hide();
	});*/
	$("a.tooltip").hover(function(){
		$("div.tool_tip").show();
	},function(){
		$("div.tool_tip").hover(function(){$("div.tool_tip").show();},function(){$("div.tool_tip").hide();});
	});
	
	$("div.thumbs_img li").click(function() {
		var curRel = $("a", $(this)).attr('hrefS'); 	
		
		$("div.thumbs_img li").removeClass('active');
		
		$("img.large_img", $("div.photo")).attr('src', curRel);
		//$("a.large_img1", $("div.zoom")).attr('href', curRel);
		$(this).addClass('active');
		
		return false;
	});
	
	$("a[rel=productImages]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Photo ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	
	$("div.tab li").click(function() {
		var curRel = $("a", $(this)).attr('rel');							
		
		$("div.tab_content_block").hide();
		$("div.tab li").removeClass('active');
		
		$(this).addClass('active');
		$("div." + curRel).show();
		
		return false;
	});

	$("div.tabs li").click(function() {
		var curRel = $("a", $(this)).attr('rel');							
		
		$("div.tabs_content_block").hide();
		$("div.tabs li").removeClass('active');
		
		$(this).addClass('active');
		$("div.#" + curRel).show();
		
		return false;
	});
	
	
	
		$("a.videopopup").fancybox({
			'overlayShow': true,
			'frameWidth':		480, 
			'frameHeight':		376,
                            'overlayOpacity': 0.6/*,
			'easingIn': 'easeOutBack',
			'easingOut': 'easeInBack',
			'zoomSpeedIn'			: 600,
			'zoomSpeedOut'			: 500,
			'hideOnContentClick': false*/
		});	
	
});

$(document).ready(function(){

$(".cart").load('/app/ajax.do?action=ShowShoppingProducts&rnd='+Math.random());

});


function bookmark(link, productId, actionType) {
	$.post(link,
			{action:'UpdateCustomerFavorite',productId:productId,type:actionType},
			function(data){
					if("DELETE"==actionType) {
						$('#bookmarkImg').attr('src','/common/images/bookmark_icon.gif');
					} else{
						$('#bookmarkImg').attr('src','/common/images/bookmark_icon_on.gif');
					}
				 });
	
}

function bookmarkOnCustomerFav(link, productId, actionType) {
	$.post(link,
			{action:'UpdateCustomerFavorite',productId:productId,type:actionType},
			function(data){
					$('.'+productId).hide();
					
				 });
	
}



function deleteProduct(delObjName) {
	$.get($('#'+delObjName).attr('delhref')+'&rnd='+Math.random());
	$(".cart").load('/app/ajax.do?action=ShowShoppingProducts&rnd='+Math.random());
	
}

function assignValueFrom(source, destination,type) {
	if ('combo'==type) {
		document.getElementById(destination).selectedIndex = document.getElementById(source).selectedIndex;
		
	}else {
		$('#'+destination).val($('#'+source).val());
	}
}



function cambiaColor(id){
	if(document.getElementById('product_'+id).className!="ilumina"){
		document.getElementById('product_'+id).className = "ilumina";
	}else{
		document.getElementById('product_'+id).className = "inner_heading";
	}
	
}


















