﻿//start mailing list js			
	


	$(document).ready( function() {		


	if (navigator.appVersion.indexOf("Win")!=-1) {
		
	}else{
		if ($.browser.mozilla){
			var st = document.createElement("link");
			st.setAttribute("rel","stylesheet");
			st.setAttribute("href","templates/deluxe/css/mac_css.css");
			document.body.appendChild(st);	
		};			
	}

		$('#back').load(function(){
			$('#i0').css('display', 'block');
			$('#foot_img').css('display', 'block');
		});		
		
		
		$('#i0').css( {'top':'464px', 'left':'464px'} );
	
		form_cache = $('.wrapping_box1 .wrap_form').html(); //cache of mailing list form for refreshing
		
		$( "a[title='Join Our Mailing List']" ).click( function() {
			if ($('form#maillistform').length == 0 && $('form#xlsws_category').length > 0) {
				$('form#xlsws_category').attr('onsubmit', 'return check_form(this)');
			}
			$('.wrapping_box1').fadeIn(500);
			$('.wrap_form').fadeIn(500);
			if($('div.wrap_form').is(':visible')){
				stopAnimation();
				$('.fsubmit').css({'background-position':'0 1000'});
				$('.fsubmit').removeClass('thank');
			}
			return false;
		} )
	
		$('.btn_close').click( function() {
			if ($('form#maillistform').length == 0 && $('form#xlsws_category').length > 0) {
				$('form#xlsws_category').attr('onsubmit', '');
			}
			$('.wrapping_box1').fadeOut(500);
			animate_bg();
			return false;
		} )
		
		
		$('.fname').focus( function() {
			$(this).addClass('hover');
		})
		$('.fname').focusout(function() {
			if ($(this).val() == '') $(this).removeClass('hover');
		})
		$('.fname2').focus( function() {
			$(this).addClass('hover');
		})
		$('.fname2').focusout(function() {
			if ($(this).val() == '') $(this).removeClass('hover');
		})
		
		$('.select_items').click( function() {
			if ($('.title_select').css('display') == 'block') {
				$('.title_select').hide();
			} else {
				$('.title_select').show();
			}
		})
		
		$('.title_select li a').click( function() {
			$('.title_select').hide();
			title = $(this).attr('title');
			if (title == 'MR.') $('.select_items').css('background','url("img/select_items2.png") 0 0 no-repeat');
			if (title == 'MS.') $('.select_items').css('background','url("img/select_items2.png") 0 -18px no-repeat');
			if (title == 'DR.') $('.select_items').css('background','url("img/select_items2.png") 0 -36px no-repeat');
			$('.ftitle').attr("value", title);
		})
		
		$('.f_img').css( { 'display':'none' } );
		 
		$('#i10').load( function() {
			animate_bg();
		}); 
		
		step = 0;
		sum = 0;
		timeout = new Array();
		time = new Array(1000, 1500, 1000, 3500, 1500, 1000, 2500, 1500, 1500, 3500, 2000, 1000, 1000, 2500, 1500, 2000, 4000, 2000, 2000, 2500, 2000, 1500);
		max_timeout = 21;
		
		

		
		
});
	function stopAnimation() {
		for (i = step; i <= max_timeout; i++) {
			clearTimeout(timeout[i]);
		}
	}
	function sum_time(first_step, current_step) {
		sum = 0;
		for (i = first_step; i < current_step + 1; i++) {
			 
				sum += time[i];
			 
			
		}
		return sum;
	}

	function animate_bg() {
		setTimeout(function() {
			timeout[1] = setTimeout( function() {
							if (step == 0) {
								$('#i0').fadeIn(790, function() {step = 1;});
							}
						}, sum_time(step, 0) );	
			 timeout[2] = setTimeout( function() {
							if (step == 1) {
								$('#i0').fadeOut(790, function() {step = 2;});
							}	
						}, sum_time(step, 1) );
					
			timeout[3] = setTimeout( function() {
							
							if (step == 2) {
								$('#i1').css({'top':'117px', 'left':'373px'});
								$('#i1').fadeIn(790, function() {step = 3;} );
							}
						}, sum_time(step, 2));
						
			timeout[4] = setTimeout( function() {
				 
							if (step == 3) {
								$('#i1').fadeOut(790, function() {step = 4;});
							}
						}, sum_time(step, 3) );
						
			timeout[5] = setTimeout( function() {
							if (step == 4) {
								$('#i2').css({'top':'434px', 'left':'620px'});
								$('#i2').fadeIn(600, function() {step = 5;});
							}	
						}, sum_time(step, 4)  );
						
			timeout[6] = setTimeout( function() {
							if (step == 5) {
								$('#i3').css({'top':'591px', 'left':'381px'});
								$('#i3').fadeIn(500, function() {step = 6;});
							}	
						}, sum_time(step, 5) );
						
			timeout[7] = setTimeout( function() {
							if (step == 6) {
								$('#i2').fadeOut(800, function() {step = 7;});
							}	
						}, sum_time(step, 6)  );
						
			timeout[8] = setTimeout( function() {
							if (step == 7) {
								$('#i3').fadeOut(800, function() {step = 8;});
							}
						}, sum_time(step, 7) );
						
			timeout[9] = setTimeout( function() {
							if (step == 8) {
								$('#i4').css({'top':'504px', 'left':'477px'});
								$('#i4').fadeIn(500, function() {step = 9;});
							}	
						}, sum_time(step, 8) );
						
			timeout[10] = setTimeout( function() {
							if (step == 9) {
								$('#i4').fadeOut(500, function() {step = 10;});
							}	
						}, sum_time(step, 9)  );
			
			timeout[11] = setTimeout( function() {
							if (step == 10) {
								$('#i5').css({'top':'430px', 'left':'425px'});
								$('#i5').fadeIn(400, function() {step = 11;});
							}	
						}, sum_time(step, 10)  );
						
			timeout[12] = setTimeout( function() {
							if (step == 11) {
								$('#i6').css({'top':'158px', 'left':'879px'});
								$('#i6').fadeIn(500, function() {step = 12;});
							}
						}, sum_time(step, 11)  );
						
			timeout[13] = setTimeout( function() {
							if (step == 12) {
								$('#i7').css({'top':'571px', 'left':'615px'});
								$('#i7').fadeIn(500, function() {step = 13;});
							}
						}, sum_time(step, 12) );
			
			timeout[14] = setTimeout( function() {
							if (step == 13) {
								$('#i5, #i6, #i7').fadeOut(500, function() {step = 14;});
							}
						}, sum_time(step, 13)  );
			
			timeout[15] = setTimeout( function() {
							if (step == 14) {
								$('#i8').css({'top':'429px', 'left':'495px'});
								$('#i8').fadeIn(400, function() {step = 15;});
							}	
						}, sum_time(step, 14)  );
						
			timeout[16] = setTimeout( function() {
							if (step == 15) {
								$('#i9').css({'top':'377px', 'left':'753px'});
								$('#i9').fadeIn(400, function() {step = 16;});
							}
						}, sum_time(step, 15)  );
						
			timeout[17] = setTimeout( function() {
							if (step == 16) {
								$('#i8, #i9').fadeOut(700, function() {step = 17;});	
							}	
						}, sum_time(step, 16)  );
						
			timeout[18] = setTimeout( function() {
							if (step == 17) {
								$('#i10').css({'top':'-1px', 'left':'428px'});
								$('#i10').fadeIn(600, function() {step = 18;});
							}	
							
						}, sum_time(step, 17)  );
			
			timeout[19] = setTimeout( function() {
							if (step == 18) {
								$('#i11').css({'top':'-1px', 'left':'891px'});
								$('#i11').fadeIn(600, function() {step = 19;} );
							}	
						}, sum_time(step, 18) );
						
			timeout[20] = setTimeout( function() {
							if (step == 19) {
								$('#i10').fadeOut(600, function() {step = 20;});	
							}
						}, sum_time(step, 19)  );
						
			timeout[21] = setTimeout( function() {
							if (step == 20) {
								$('#i11').fadeOut(600, function() {step = 21;});	
							}
						}, sum_time(step, 20)  );
						
			timeout[22] = setTimeout( function() {
			
							if (step == 21) {
								
								$('#i0').fadeIn(790, function() {step = 0; animate_bg(); });
							}
						}, sum_time(step, 21) );	
			
		}, 700);
	} 		

var form_cache = '';
function check_form(frm)
{
	if( $('#maillistform .ftitle').val().length == 0 ) {
		alert("'TITLE' is required.");
		return false;
	}
	
   if(frm.fname.value=="")
   {
       alert("'NAME' is required.");
       return false;
   }

   if(frm.fmail.value=="")
   {
       alert("'EMAIL ADDRESS' is required.");
       return false;
   }

   var pattern = '^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$';
   if(!frm.fmail.value.match(new RegExp(pattern)))
   {
       alert("'EMAIL ADDRESS' is in incorrect format.");
       return false;
   }

   if(frm.fstate.value=="")
   {
       alert("'STATE' is required.");
       return false;
   }

   $.post('/savemail.php?mode=savemaillist', $("#maillistform").serialize(),

        function(data)
        {
			$('.fsubmit').css({'background-position':'0 0'});
			$('.fname').val('').removeClass('hover');
			$('.fname2').val('').removeClass('hover');
			$('.fmail').val('');
			$('.fstreet').val('');
			$('.fcity').val('');
			$('.fstate').val('');
			$('.fzip').val('');
            $('.wrap_form').delay(1000).fadeOut(500, function(){
				$('.fsubmit').css({'background-position':'0 1000px'});
				$('.fsubmit').removeClass('thank');
				if ($('form#maillistform').length == 0 && $('form#xlsws_category').length > 0) {
					$('form#xlsws_category').attr('onsubmit', '');
				}
				animate_bg();
			});
			
        }

   );

   return false;
}

// end mailing list js






$(document).ready(function(){
$('img.long').parents('.jMyCarousel').addClass('padTop0');


$('.box_close').click(function() {
//alert('321');
})


$('.narrow_select1').click(function() {
$('.cust_s9').css('z-index','70');
})



$('.narrow_select2').click(function() {
$('.cust_s9').css('z-index','70');
})


$('.cust_s9').click(function() {
$('.cust_s9').css('z-index','100');
})

//index.php - GO TO PRODUCT -> begin
if( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) ) {
	var product_id = '';
	
	if ( window.location.pathname.split('/').length > 2 && window.location.href.indexOf("#/") === -1 ) {
		product_id = window.location.pathname.split('/')[window.location.pathname.split('/').length - 1];
	}
	
	else if ( window.location.href.indexOf("#/") !== -1 ) { 
		product_id = window.location.href.split("#/")[window.location.href.split("#/").length - 1];
	}

	if ( product_id !== '' ) {
			$(".jMyCarousel").jMyCarousel({
				auto: true,
				visible: '1024px',
				btnPrev: $('#carouselRight'),
				btnNext: $('#carouselLeft'),
				evtStart: 'click',
				evtStop: null
			});

			$('.land').hide();
			if ( $(".jMyCarousel a[onclick*=" + product_id + "]").length > 0 ) {
				$(".jMyCarousel a[onclick*=" + product_id + "]").children('img').trigger('click').addClass('active_item').css('opacity', '1');
				setTimeout(function(){
					if ($(".jMyCarousel a[onclick*=" + product_id + "]").parent().parent().prevAll().length <= 5) {
						var curr_position = $(".jMyCarousel a[onclick*=" + product_id + "]" +" img").offset().left - $("div.jMyCarousel").offset().left;
						var new_left = 600 - curr_position;
						$("div.jMyCarousel ul").animate({left:"+=" + new_left},{queue:false, duration:50});
					}
				}, 1000);
			}
			setTimeout(function(){
				$('.cw, .cw li img').css({ opacity : 1 });
				$('.navi').css({ opacity : 1 });
			}, 1300);
	}

	//New Things - GO TO PRODUCT -> begin
	if ( product_id > 0 && $('.new_things_page').length > 0 && $('#prod_new'+product_id).length > 0 ) {
		$('#maindiv, .land').hide();
		$('#prod_new'+product_id).trigger('click');
		setTimeout( function(){
			$('.new_things_active').removeClass('new_things_active');
			$('.cw .inside_scrolable img').css({ opacity : 0.7 });
			$('#prod_new'+product_id).css({ opacity : 1 }).addClass('new_things_active');
		}, 1000);
	}//New Things - GO TO PRODUCT -> end
}
//index.php - GO TO PRODUCT -> end

// CREATE NEW WISHLIST -> begin

var params = {
	changedEl: ".create_new_wishlist .custom_select select",
	visRows: 5,
	scrollArrows: true
};
cuSel(params);

//--------------viktor 19 10 2011---------------

	var cuselVal=[];
	for (i=2; i<=5; i++){
		optVal=$('.cust_s'+i).find('option:first').val();
		optAttrSelected=$('.cust_s'+i).find('option:first').attr('selected');
		
		if(typeof(optVal)=='string' && optVal!='undefined' && optVal!='Diamonds - colored' && optVal!='Gold - white' && optVal!='Gold - pink' && optAttrSelected=='selected'){
		  cuselVal[i]=optVal;
		  //alert(optVal);
		  $('.cust_s'+i).find('option:first').remove();
		  //alert(optVal);
		}
	}
	if (typeof($('#reg_form_post')[0])=='object'){
		if_cuSel_done = setInterval(function(){
			if(typeof($('.cust_s1 .custom_select #cuselFrame-favoritejewelery'))=='object'){	
								for (i=2; i<=5; i++){
									//alert(cuselVal[i]);
							      $('.cust_s'+i).find('span').each(function(){
									  
												  if ($(this).html() == 'Other - enter' && cuselVal[i]) {
													 $(this).attr('val',cuselVal[i]);
													 //alert(cuselVal[i]);
													 var new_name = $(this).parents('.cusel').children('input[type="hidden"]').attr('name');
													 //alert(new_name);
													 $('#'+new_name).parent('.cusel').append('<input id="'+ new_name +'_input" value="'+cuselVal[i]+'" type="text" name="' + new_name + '_input"/>');
				 									 
									}
								});
					           }
					   
				$('.cuselFrameRight').unbind('click', backToSelect).click(backToSelect);
				clearInterval(if_cuSel_done);
			}
		}, 500);
	}

		
//--------------viktor 19 10 2011---------------


	$('.btn_save input, .btn_cancel input').attr('value', '');
	
//removes span with id=c42_ctl on the wishlist creation page 
	$('.custom_select.custom_wishlist').html($('.custom_select.custom_wishlist > span').html());

    
// CREATE NEW WISHLIST <- end


// SEARCH FUNCTIONALTY -> begin
	$('.search-submit').click(function(){
		//ie cusel double quotes fix -> begin
		if( navigator.userAgent.indexOf('MSIE 8') !== -1 ) {
			var fixIEOpenOpenCloseCloseQuotesBug = function() {
				var inps = document.querySelectorAll('#f_metal, #f_gems, #f_price'),
					inpsLength = inps.length,
					iii;
					
				for ( iii = 0; iii < inpsLength; iii++ ) {
					if( inps[iii].value.indexOf('"') == 0 ){
						inps[iii].value = inps[iii].value.substr(1, inps[iii].value.length - 2);
					}
				}
			}
			fixIEOpenOpenCloseCloseQuotesBug();
		}
		//ie cusel double quotes fix <- end
		
		$(this).parents('form').each(function(){
			$(this).attr('action', '/search');
		});
		return true;
	});
	
	$('.btn-advanced-search').click(function(){
		/*jQuery(document).ready(function(){
			var params = {
					changedEl: ".advanced-search .custom_select select",
					visRows: 5,
					scrollArrows: true
				}
				cuSel(params);
		});*/
		if ($('.advanced-search').css('display') == 'none') {
			$('.advanced-search').fadeIn(500);
		}
		else {
			$('.advanced-search').fadeOut(500);
		}
		var params = {
					changedEl: ".advanced-search .custom_select select",
					visRows: 5,
					scrollArrows: true
				}
				cuSel(params);
				$('.custom_select').click(function(){
					$(this).find('span').each(function(){
						if ($(this).html() == 'Other - enter') {
							$(this).unbind('click', otherSelect);
							$(this).click(otherSelect);
						}
					});
				});
		
		return false;
	});
// SEARCH FUNCTIONALTY <- end

	
// SHOPING CART -> begin
	$('.cart-step-1 .cart-btn-check').click(function(){
		$('.cart-step-1').css({'position':'absolute'}).fadeOut(500);
		$('.cart-step-2').css({'position':'relative'}).fadeIn(500);
		var params = {
			changedEl: ".cart-step-2 .custom_select2 select",
			visRows: 5,
			scrollArrows: true
		};
		cuSel(params);
		return false;
	});
	
	if ($('.cart-step-2 .custom_select2 select:visible').length > 0) {
		var params = {
			changedEl: ".cart-step-2 .custom_select2 select",
			visRows: 5,
			scrollArrows: true
		};
		cuSel(params);
	}
	
	$('.cart-step-2 .link-proceed-to-pay').click(function(){
		$('.cart-step-2').css({'position':'absolute'}).fadeOut(500);
		$('.cart-step-3').css({'position':'relative'}).fadeIn(500);
		var params = {
			changedEl: ".cart-step-3 .custom_select select",
			visRows: 5,
			scrollArrows: true
		};
		cuSel(params);
		return false;
	});
	
	$('.cart-step-3 .reg-block2 .niceCheck').click(function(){
		if ($(this).children('input').attr('checked')) {
			var i = 0;
			$('.reg-block2 input:gt(0)').each(function(){
				$(this).val($('.reg-block3 input')[i].value);
				i++;
			});
			$('.reg-block2 .cusel-scroll-pane').html('');
			$('.reg-block3 .cusel-scroll-pane').children().clone().appendTo('.reg-block2 .cusel-scroll-pane');
			$('.reg-block2 .cuselText').html($('.reg-block3 .cuselText').html());
		}
	});
	
	$('.cart-step-3 .link-proceed-to-pay').click(function(){
		/*form validation part*/
		var isValid = true;
		var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
		var reg_phone = /^[0-9-\s]*$/;
		var zip_reg = /^[0-9-\s]*$/;
		$('.cart-step-3 .err_color').removeClass('err_color');
		$('.cart-step-3 #billstreet1, .cart-step-3 #shipstreet1').each(function(){
			if ($(this).val() == '') {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		$('.cart-step-3 #billcity, .cart-step-3 #shipcity').each(function(){
			if ($(this).val() == '') {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		$('.cart-step-3 #billstate, .cart-step-3 #shipstate').each(function(){
			if ($(this).siblings('.cuselText').html() == '-- Select One --') {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		$('.cart-step-3 #billzip, .cart-step-3 #shipzip').each(function(){
			if ($(this).val() == '' || !$(this).val().match(zip_reg)) {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		if ($('.cart-step-3 #f_email').val() == '' || !$('.cart-step-3 #f_email').val().match(reg)) {
			isValid = false;
			$('.cart-step-3 #f_email').parents('dd').prev('dt').children('label').addClass('err_color');
		}
		if ($('.cart-step-3 #f_email_conf').val() == '' || $('.cart-step-3 #f_email').val() !== $('#f_email_conf').val()) {
			isValid = false;
			$('.cart-step-3 #f_email_conf').parents('dd').prev('dt').children('label').addClass('err_color');
		}
		if ($('.cart-step-3 #f_telephone').val() == '' || !$('.cart-step-3 #f_telephone').val().match(reg_phone)) {
			isValid = false;
			$('.cart-step-3 #f_telephone').parents('dd').prev('dt').children('label').addClass('err_color');
		}
		if (!isValid) {
			$('.cart-step-3 p.err_msg').show();
		}
		else {
			$('.cart-step-3 p.err_msg').hide();
			$('.cart-step-3').css({'position':'absolute'}).fadeOut(500);
			$('.cart-step-4').css({'position':'relative'}).fadeIn(500);
			var params = {
				changedEl: ".cart-step-4 .custom_select select",
				visRows: 5,
				scrollArrows: true
			};
			cuSel(params);
		}
		/*END of form validation part*/
		return false;
	});
	
	$('.cart-step-4 .link-submit-info').click(function(){
		/*form validation part*/
		var isValid = true, i = 0;
		var cart_reg = /^[0-9-\s]*$/;
		var pin_reg = /^[0-9]*$/;
		$('.cart-step-4 .err_color').removeClass('err_color');
		var name_reg = /^[a-zA-Z\'` ]*$/;
		if ($('.cart-step-4 #credit_card_type').val() == '0') {
			isValid = false;
			$('.cart-step-4 #credit_card_type').siblings('.cuselText').addClass('err_color');
		}
		$('.cart-step-4 #f_fname, .cart-step-4 #f_lname').each(function(){
			if ($(this).val() == '' || !$(this).val().match(name_reg)) {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		if ($('.cart-step-4 #f_card_numb').val() == '' || !$('.cart-step-4 #f_card_numb').val().match(cart_reg)) {
			isValid = false;
			$('.cart-step-4 #f_card_numb').parents('dd').prev('dt').children('label').addClass('err_color');
		}
		$('.cart-step-4 #exp_month').val()
		$('.cart-step-4 .exp_date input[type=hidden]').each(function(){
			var today = new Date();
			if ($(this).val() == '0' || ($('.cart-step-4 #exp_year').val() <= today.getFullYear() && $('.cart-step-4 #exp_month').val() < today.getMonth() + 1)) {
				isValid = false;
				$(this).parents('dd').prev('dt').children('label').addClass('err_color');
			}
		});
		if ($('.cart-step-4 #f_security_numb').val() == '' || !$('.cart-step-4 #f_security_numb').val().match(pin_reg)) {
			isValid = false;
			$('.cart-step-4 #f_security_numb').parents('dd').prev('dt').children('label').addClass('err_color');
		}
		if ($('.cart-step-4 #f_no_include').attr('checked') != 'checked') {
			isValid = false;
			$('.cart-step-4 #f_no_include').parents('.niceCheck').siblings('p').addClass('err_color');
		}
		if (!isValid) {
			$('.cart-step-4 p.err_msg').show();
		}
		else {
			$('.cart-step-4 p.err_msg').hide();
			$('.cart-step-4').css({'position':'absolute'}).fadeOut(500);
			$('.cart-step-5').css({'position':'relative'}).fadeIn(500);

                           $.post('/lib.php?mode=calculateIL', $("#cartform").serialize(),

                            function(data){
                              document.getElementById("resulttotal").innerHTML = '$'+data;
                              document.getElementById("resulttotal2").innerHTML = '$'+data;
                           });


		}
		/*END of form validation part*/
		$('.cart-step-5 .reg-block1 dd > p:eq(0), .cart-step-5 .reg-block2 dd > p:eq(0)').html($('.cart-step-4 #f_fname').val());
		$('.cart-step-5 .reg-block1 dd > p:eq(1), .cart-step-5 .reg-block2 dd > p:eq(1)').html($('.cart-step-4 #f_lname').val());
		$('.cart-step-5 .reg-block1 dd > p:gt(1)').each(function(){
			var elem = $('.cart-step-3 .reg-block3 dd input:gt(0)').not('input[type=checkbox]')[i];
			if (elem.type == 'text') {
				if ($(elem).attr('id') == 'billstreet1') {
					$(this).html(elem.value + ' ' + $('.cart-step-3 #billstreet2').val());
					i++;
				}
				else {
					$(this).html(elem.value);
				}
			}
			else {
				$(this).html($(elem).siblings('.cuselText').html());
			}
			i++;
		});
		i = 0;
		$('.cart-step-5 .reg-block2 dd > p:gt(1)').each(function(){
			var elem = $('.cart-step-3 .reg-block2 dd input:gt(0)').not('input[type=checkbox]')[i];
			if (elem.type == 'text') {
				if ($(elem).attr('id') == 'shipstreet1') {
					$(this).html(elem.value + ' ' + $('.cart-step-3 #shipstreet2').val());
					i++;
				}
				else {
					$(this).html(elem.value);
				}
			}
			else {
				$(this).html($(elem).siblings('.cuselText').html());
			}
			i++;
		});
		i = 0;
		$('.cart-step-5 .reg-block3 dd > p').each(function(){
			var elem = $('.cart-step-4 .reg-block1 dd input')[i];
			if (elem.type == 'text') {
				if ($(elem).attr('id') == 'f_fname') {
					i++;
					$(this).html(elem.value + ' ' + $('.cart-step-4 #f_lname').val());
					if (parseInt($(this).height()) > 16) {
						$(this).parent('dd').css('height', parseInt($(this).height()));
						$(this).parent('dd').prev().css('height', parseInt($(this).height()));
					}
				}
				else if ($(elem).attr('id') == 'f_card_numb') {
					$(this).html('xxxx-xxxx-xxxx-' + elem.value.substr(elem.value.length - 4, 4));
				}
				else {
					$(this).html(elem.value);
				}
			}
			else if ($(elem).attr('id') == 'exp_month') {
				$(this).html($('.cart-step-4 #exp_month').val() + ' / ' + $('.cart-step-4 #exp_year').val());
				i++;
			}
			else {
				$(this).html($(elem).siblings('.cuselText').html());
			}
			i++;
		});
		return false;
	});
	
	$('.cart-step-5 .link-place-my-order').click(function(){
//		$('.cart-step-5').css({'position':'absolute'}).fadeOut(500);
//		$('.cart-step-6').css({'position':'relative'}).fadeIn(500);
		return false;
	});
	
	$('.cart-step-5 .link-wrong-info').click(function(){
		$('.cart-step-5').css({'position':'absolute'}).fadeOut(500);
		$('.cart-step-3').css({'position':'relative'}).fadeIn(500);
		return false;
	});
	
	$('.cart-step-3 .c_yes, .cart-step-3 .c_no').click(function(){
		if ($(this).children('input').attr('checked') == "checked") {
			//$(this).children('input').attr('checked', false);
			$(this).parents('.reg-checkbox').siblings('.reg-checkbox').children('span').css('background-position','0 0').children('input').attr('checked', false);
		}
		else {
			//$(this).children('input').attr('checked', true);
			$(this).parents('.reg-checkbox').siblings('.reg-checkbox').children('span').css('background-position','0 -10px').children('input').attr('checked', true);
		}
	});
	
// SHOPING CART <- end

	
	var zoomer_long = false;
	
// ==== Piece for landingpage animation ==== //

	/*$('.land img').waitForImages( {
			finished:function() {
				$('.land_shop').css( { 'display':'block' } );
			},
			waitForAll:false	
		}
	);*/
	$('.land_shop').css( { 'display':'block' } );
	$('.land_shop').click(function(){
		
		$('.cw, .cw li img').css({ opacity : 1 });
		$('.navi').css({ opacity : 1 });
		$('.land').fadeOut(1100);
		
		setTimeout(function(){
			$(".jMyCarousel").jMyCarousel({
				auto: true,
				visible: '1024px',
				btnPrev: $('#carouselRight'),
				btnNext: $('#carouselLeft'),
				evtStart: 'click',
				evtStop: null
			});
		}, 1600);
		
		return false;
	});
	
// ==== End of Scripts for landingpage animation ==== //

// ==== Piece for press page showing/hiding pdf link ==== //
	if( $('#pressdiv3').length > 0 ) {
		if ( $('#pressdiv3').attr('href').indexOf('.pdf') == -1 ) {
			$('#pressdiv3').fadeOut(200);
		}
	}	
	else {
		$('#pressdiv3').fadeIn(200);
	}
	
// ==== End piece for press page ==== //

// ==== Piece for contact us page showing/hiding input fields ==== //
	if( $('.write_to_us').length > 0 ) {
	
		$('.write_to_us').click(function(){
			$('.name-email-fields').show();
		});
		
		$('.learn-more td.first').click(function(){
			$('.name-email-fields').hide();
		});
	}
// ==== End of piece for contact us page ==== //


	/*Garber Giving pages*/
	
	var temp = document.URL;
	var url = temp.toString();
	var pagenum = location.hash;
	
	$('.tabs li a.active').removeClass('active');
	
	$('.garber_giving .content .cols').not('.garber_giving.barneys .content .cols').hide();
	
	if ( pagenum == '#our-philosophy' ){
		$('.philosophy').addClass('curr').show();
		$('.tabs li a.philosophy').addClass('active');
	} else if ( pagenum == '#our-commitment' ){
		$('.commitment').addClass('curr').show();
		$('.tabs li a.commitment').addClass('active');
	} else if ( pagenum == '#our-philanthropy' ){
		$('.philanthropy').addClass('curr').show();
		$('.tabs li a.philanthropy').addClass('active');
	} else {
		$('.philosophy').addClass('curr').show();
		$('.tabs li a.philosophy').addClass('active');
	};
	
	
	var slideShowInterval;
	$('.tabs li a').click(function(){
		if ($(this).hasClass('active')) {
			return false;
		}
		$('.tabs li a.active').removeClass('active curr');
		var tabClass = $(this).attr('class');
		$(this).addClass('active');
		if ($('.garber_giving .cols.curr').length == 0) {
			$('.garber_giving .cols.philosophy').addClass('curr');
		}
		$('.garber_giving .cols.curr').removeClass('curr').fadeOut(800, function(){
			$('.garber_giving .cols.' + tabClass).addClass('curr').fadeIn(800);
		});
		if (tabClass == 'philanthropy' && $('.philanthropy .image img').length > 1) {
			if ($('.philanthropy .image img.curr').length == 0) {
				$('.philanthropy .image img:first-child').addClass('curr');
			}
			$('.philanthropy .image img:not(.curr)').css('display', 'none');
			slideShowInterval = setInterval(function(){
				$('.philanthropy .image img.curr').removeClass('curr').fadeOut(800, function(){
					if ($(this).next().length > 0) {
						$(this).next().addClass('curr').fadeIn(800);
					}
					else {
						$('.philanthropy .image img:first-child').addClass('curr').fadeIn(800);
					}
				});
			}, 5000);
		}
		else {
			clearInterval(slideShowInterval);
		}
	});
	
	$('.post_wrapper a.view_link').click(function(){
		if ($(this).html() == 'VIEW LESS') {
			$(this).html('VIEW MORE');
			if ($(this).siblings('.post_text').length == 0) {
				return false;
			}
			var height = $(this).siblings('.post_text').height();
			var time = height*2;
			$(this).siblings('.post_text').animate({'padding-bottom': '0px'}, 40);
			$(this).siblings('.post_text').css({'max-height': '500px', 'height': height}).animate({'height': '0px'}, time);
		}
		else {
			$(this).html('VIEW LESS');
			if ($(this).siblings('.post_text').length == 0) {
				return false;
			}
			$(this).siblings('.post_text').animate({'padding-bottom': '11px'}, 40, function(){
				$(this).css({'max-height': '0', 'height': 'auto'}).animate({'max-height': '500px'}, 1000);
			});/*
			$(this).siblings('.post_text').css({'max-height': '0', 'height': 'auto'}).animate({'max-height': '500px'}, 1000, function(){
				$(this).animate({'padding-bottom': '11px'}, 40);
			});*/
		}
	});
	/*END OF Garber Giving pages*/
	
	//GARBER STYLE -> begin //11.01.2011
	(function(){
		var url = document.URL.toString(),
			pagenum = url[url.length - 1];
		
		$('.subnavigation-gs a').removeClass('active');
		
		if ( pagenum === '2' ) {
			$('.subnavigation-gs a.gs-quality').addClass('active');
			$('.wrap-integrity, .wrap-layouts').hide();
			$('.wrap-quality').show();	
		}
		
		else if ( pagenum === '3' ) {
			$('.subnavigation-gs a.gs-integrity').addClass('active');
			$('.wrap-quality, .wrap-layouts').removeClass('curr').hide();
			$('.wrap-integrity').show();		
		}
		
		else {
			$('.subnavigation-gs a.gs-style').addClass('active');
			$('.wrap-quality, .wrap-integrity').removeClass('curr').hide();
			$('.wrap-layouts').show();	
		}
		
		$('.subnavigation-gs a').click( function(){
			if ($(this).hasClass('active')) {
				return false;
			}
			else {
				$('.subnavigation-gs a.active').removeClass('active');
				if ( $(this).hasClass('gs-style') ) {
					$('.subnavigation-gs a.gs-style').addClass('active');
					$('.wrap-quality, .wrap-integrity').filter(':visible').fadeOut( 800, function(){
						$('.wrap-layouts').fadeIn( 800 );
					} );
				}
				else if ( $(this).hasClass('gs-quality') ) {
					$('.subnavigation-gs a.gs-quality').addClass('active');
					$('.wrap-integrity, .wrap-layouts').filter(':visible').fadeOut( 800, function() {
						$('.wrap-quality').fadeIn( 800 );
					} );	
				}
				else if ( $(this).hasClass('gs-integrity') ) {
					$('.subnavigation-gs a.gs-integrity').addClass('active');
					$('.wrap-quality, .wrap-layouts').filter(':visible').fadeOut( 800, function() {
						$('.wrap-integrity').fadeIn( 800 );
					} );
				}
			}
		} );
	})();
	//GARBER STYLE <- end
	
	/*BEGIN OF About us page*/
	if ($('body.about_us').length > 0) {
		(function(){
			var url = document.URL.toString(),
				pagenum = url[url.length - 1],
				tabs = ['our-store', 'our-founder', 'our-friendship', 'stockists', 'personal-shoppers'],
				tabClass = tabs[0],
				temp_img_url = $('.about_us .img_set img.photo1').attr('src'),
				hash = location.hash;
			if ( hash !== "" ) {
				tabClass = location.hash.substr(1);
			}
			$('.subnavigation-about li a.active').removeClass('active');
			$('.subnavigation-about li a.' + tabClass).addClass('active');
			$('.about_us .content .cols').hide();
			$('.about_us .cols.' + tabClass).addClass('curr').fadeIn(800);
			
			$('.about_us .img_set img.photo1').not('full_color').addClass('clicked').attr('src', $('.about_us .img_set img.photo1.full_color').attr('src'));
			$('.about_us .img_set img.photo1.full_color').attr('src', temp_img_url);
			
			$('.subnavigation-about li a').click(function(){
				if ($(this).hasClass('active')) {
					return false;
				}
				$('.subnavigation-about li a.active').removeClass('active');
				var tabClass = $(this).attr('class');
				$(this).addClass('active');
				if ($('.about_us .cols.curr').length == 0) {
					$('.about_us .cols.our-store').addClass('curr');
				}
				$('.about_us .cols.curr').removeClass('curr').fadeOut(800, function(){
					$('.about_us .cols.' + tabClass).addClass('curr').fadeIn(800);
				});
			});
		})();
	}
	
	var is_end_anim = true;
	$('.about_us .img_set img').click(function(){
		if ($(this).hasClass('clicked') || !is_end_anim) {
			return false;
		}
		is_end_anim = false;
		var img_class = $(this).attr('class');
		if ( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) ) {
			var bw_img_url = $(this).attr('src'),
				col_img_url = $('.img_set img.' + img_class + '.full_color').attr('src'), //full color image url of cliked element
				prev_col_img = $('.img_set img.clicked').attr('src'); //full color image url of previous cliked element
			if ($('.img_set img.clicked').length > 0) {
				var prev_img_class = $('.img_set img.clicked').removeClass('clicked').attr('class'),
					prev_bw_img = $('.img_set img.' + prev_img_class + '.full_color').attr('src');
				$('.img_set img.' + prev_img_class +':visible').attr('src', prev_bw_img);
				$('.img_set img.' + prev_img_class + '.full_color').attr('src', prev_col_img);
			}
			$('.img_set img.' + img_class + '.full_color').attr('src', bw_img_url);
			$(this).attr('src', col_img_url);
			$(this).addClass('clicked');
		}
		else {
			$('.img_set img.clicked').removeClass('clicked');
		}
		$(this).addClass('clicked');
		$('.description_wrap div:visible').fadeOut(400, function(){
			$('.description_wrap .for_' + img_class).fadeIn(400, function(){ is_end_anim = true; });
		});
	});
	
	if (!(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPad/i))) {
		$('.about_us .img_set img').hover(function(){
			if ($(this).hasClass('clicked')) {
				return false;
			}
			//Current img
			var img_class = $(this).attr('class'),
				col_img_url = $('.img_set img.' + img_class + '.full_color').attr('src');
			$('.img_set img.' + img_class + '.full_color').attr('src', $(this).attr('src'));
			$(this).attr('src', col_img_url);
			//Previous img
			var prev_img_class = $('.clicked').attr('class').substr(0, 6),
				prev_bw_img_url = $('.img_set img.' + prev_img_class + '.full_color').attr('src');
			$('.img_set img.' + prev_img_class + '.full_color').attr('src', $('.clicked').attr('src'));
			$('.clicked').not('.full_color').attr('src', prev_bw_img_url);
		},
		function(){
			if ($(this).hasClass('clicked')) {
				return false;
			}
			//Current img
			var img_class = $(this).attr('class'),
				col_img_url = $('.img_set img.' + img_class + '.full_color').attr('src');
			$('.img_set img.' + img_class + '.full_color').attr('src', $(this).attr('src'));
			$(this).attr('src', col_img_url);
			//Previous img
			var prev_img_class = $('.clicked').attr('class').substr(0, 6),
				prev_col_img_url = $('.img_set img.' + prev_img_class + '.full_color').attr('src');
			$('.img_set img.' + prev_img_class + '.full_color').attr('src', $('.clicked').attr('src'));
			$('.clicked').not('.full_color').attr('src', prev_col_img_url);
		});
	}
	
	/*END OF About us page*/
	 
    //cut n past invities in one block with productlist
    var invit = $('#c17 #c33_ctl').detach();
    invit.appendTo('#c30_ctl .wishlist.custom .scroll-pane');
	
	
	
	//disable text-decoration in myaccount in wishlist list
	$('.w-my_acc_block div:last li a').not('.w-my_acc_block div:last li.light a').css('text-decoration','none');
    
	/*barneys page BEGIN*/
	(function(){
		if ($('body.barneys').length > 0 && $('.philanthropy .image img').length > 1) {
				if ($('.philanthropy .image img.curr').length == 0) {
					$('.philanthropy .image img:first-child').addClass('curr');
				}
				$('.philanthropy .image img:not(.curr)').css('display', 'none');
				slideShowInterval = setInterval(function(){
					$('.philanthropy .image img.curr').removeClass('curr').fadeOut(800, function(){
						if ($(this).next().length > 0) {
							$(this).next().addClass('curr').fadeIn(800);
						}
						else {
							$('.philanthropy .image img:first-child').addClass('curr').fadeIn(800);
						}
					});
				}, 4600);
			}
	})();
	/*barneys page END*/
	
	
	/*in_the_news. swich between tabs press and on the town BEGIN*/
	(function() {
		var iDevice=false,
			pageHash = location.hash;
		
		if ( (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) ) {
			iDevice=true;
		}	
		
		if ( pageHash == "#on-the-town" ) {
			$('.subnavigation-in-the-news li a').removeClass('active');
			$('.tab_on_the_town').addClass('active');
			$('.press_wrap').hide();
			$('.on_the_town_wrap').show();
			if( iDevice === true ) {
				$(window).load( function() {
					$(".on_the_townCarusell").jMyCarousel({
						auto: true,
						visible: '938px',
						btnPrev: $('#carouselRight2'),
						btnNext: $('#carouselLeft2'),
						evtStart: 'click',
						evtStop: null
					});
				} );	
			}
		}
		
	   
		$('.subnavigation-in-the-news li a').click(function(){
			$('.subnavigation-in-the-news li a').removeClass('active');
			$(this).addClass('active');
			if ($(this).hasClass('tab_press') && $('.on_the_town_wrap').is(':visible')){
				$('.content .on_the_town_wrap').fadeOut(function(){
					$('.content .press_wrap').fadeIn( function(){
						if (!($('.pressCarusell ul').is(':animated')) && iDevice){//need to start carusel wen it is visible only
							$(".pressCarusell").jMyCarousel({
								auto: true,
								visible: '938px',
								btnPrev: $('#carouselRight'),
								btnNext: $('#carouselLeft'),
								evtStart: 'click',
								evtStop: null
							});
						}						
					} );
				});
			}
			if ($(this).hasClass('tab_on_the_town') && $('.press_wrap').is(':visible')){
				$('.content .press_wrap').fadeOut(function(){
					$('.content .on_the_town_wrap').fadeIn(function(){
						if (!($('.on_the_townCarusell ul').is(':animated')) && iDevice){//need to start carusel wen it is visible only
							$(".on_the_townCarusell").jMyCarousel({
								auto: true,
								visible: '938px',
								btnPrev: $('#carouselRight2'),
								btnNext: $('#carouselLeft2'),
								evtStart: 'click',
								evtStop: null
							});
						}
					});
				});
			}
		})
	}());
	/*in_the_news. swich between tabs press and on the town END*/
	
	/*new_things start working customize scroll START*/
		           if ($('.scroll_able').length!=0){
				    var $pane = $('.scroll_able'),
					api;
					$pane.jScrollPane( {animateTo:true, showArrows:true, hijackInternalLinks:true, autoReinitialise: true} );
					api = $pane.data('jsp');
				   }
	/*new_things start working customize scroll END*/
	
	
	/*new_things hide or show pdf START*/
//		if($('#pressdiv3').attr('href')==''){$('#pressdiv3').css('display','none'); alert('pressdiv3');};
//		if($('#pressdiv32').attr('href')==''){$('#pressdiv32').css('display','none'); alert('pressdiv32');};
		
	/*new_things hide or show pdf END*/
	
	
});

//index.php - GO TO PRODUCT (IE fixing) -> begin
	var product_id = 0;
	if (window.location.search.split('p=').length > 1) {
		product_id = parseInt(window.location.search.split('p=')[1].split('&')[0]);
	}
	else if (window.location.pathname.split('/').length > 1) {
		product_id = parseInt(window.location.pathname.split('/')[window.location.pathname.split('/').length - 1]);
	}
	if (product_id > 0 && navigator.appName == "Microsoft Internet Explorer") {
		$('head').append('<style>.land { display: none; }</style>');
	}
//index.php - GO TO PRODUCT (IE fixing) -> end

var zoomer_long = false;

function otherSelect() {
	//alert('select');
	if ($(this).parents('.cusel').children('input').length === 1) {
		var new_name = $(this).parents('.cusel').children('input[type="hidden"]').attr('name') + '_input';
		$(this).parents('.cusel').append('<input id="'+ new_name +'" type="text" name="' + new_name + '">');
		$(this).parents('.cusel').children('.cuselFrameRight').unbind('click', backToSelect).click(backToSelect);
	}
	else {
		$(this).parents('.cusel').children('input').show();
	}
}

function backToSelect() {
	$(this).parents('.cusel').children('input').val('');
	$(this).parents('.cusel').children('input').hide();
	//alert('hide');
}


function show_details(id, elem) {
	window.location.hash = '/' + id;
	if (typeof(elem) == 'string') {
		var classNameRef = elem;
	}
	else {
		var classNameRef = elem.getElementsByTagName('img')[0].className;
	}
	var productMagnifiedContainer = $('.col.ip'), //caching elements
		scrollParent = $('.cw'), flash_width = 400, flash_height = 357;
		if (classNameRef === 'standard2'){flash_height = 528; flash_width = 430;};
	
	$.post('/lib.php?mode=productdetail&md=1&prid='+id, function(data){
		var ie = '\v'=='v';
		if (ie) {
			$('#worndiv > h2 img').hide();
		}
		$('#bigimage, #worndiv, #alternatediv').fadeOut(600);
		if( !( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) )  ) {
			$('.btn_zoom_block a').css( { 'zIndex':'10','display':'block' } );
		}
		$('.flash_zoom').fadeOut(600);//flash zoom fadeout
		$('#maindiv').fadeOut(600, function(){
		
			if( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) ) {
				$('#bigimage').filter('#bigimage').attr('src','').attr('src',data);
				$('#retina').css('background', 'url('+data+') no-repeat');
				$('.ajax-loader-zoom').animate({'opacity':'1'}, 100);
			}
			
			else {
				if (classNameRef === 'long') {
					flash_width = 268;
					flash_height = 513;
				}
				$('.flash_zoom').html('<div id="flash_zoom_obj"><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
				var flashvars = {
					W: flash_width,
					H: flash_height,
					urlImage: data
				};
				var params = {
					menu: "false",
					wmode: "transparent",
					scale: "noScale",
					allowFullscreen: "true",
					allowScriptAccess: "always",
					bgcolor: "#EBEBED"
				};
				var attributes = {
					id:"zoomer"
				};
				if ($('.new_things_page').length > 0){
					swfobject.embedSWF("templates/deluxe/flash/zoom_new-things.swf", "flash_zoom_obj", flash_width, flash_height, "10.0.0", "templates/deluxe/flash/expressInstall.swf", flashvars, params, attributes);
				}else{
					swfobject.embedSWF("templates/deluxe/flash/zoom.swf", "flash_zoom_obj", flash_width, flash_height, "10.0.0", "templates/deluxe/flash/expressInstall.swf", flashvars, params, attributes);
				}
			}
			
		});
		setTimeout(function(){
		
			if(  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))  ) {
				$('#worndiv, #alternatediv').html('');
				$('#bigimage').load(function(){
					$('.ajax-loader-zoom').animate({'opacity':'0'}, 100);
					setTimeout( function() {
						$('#bigimage').fadeIn(800);
					}, 300 ); 	
				});
			}
				
			else {
			
				setTimeout( function() {
					$('.btn_zoom_block a').css( { 'zIndex':'10','display':'block'  } );
					$('.flash_zoom').show();
					$('#btn_zoom').mouseover(function(){$(this).css({'z-index':'3','display':'none'})});					
				}, 400 );
				
				//setTimeout( function() {
//					$('.btn_zoom_block a').css( { 'zIndex':'3','display':'none'} );
//				}, 2100 );
				
			}
				
			$.post('/lib.php?mode=productdetail&md=11&prid='+id, function(data){
				// ==== Piece for product page  ==== //
				// switch between long and standard templates when clicking on product in the scroll
				if( classNameRef === 'standard' ) {
					zoomer_long = false;
					if( productMagnifiedContainer.hasClass('tall') ) {
						productMagnifiedContainer.removeClass('tall');
						if (typeof(elem) == 'string') {
							scrollParent.addClass('zero_padd');
						}
					}
					launchStandartZoom();
				}
				else if( classNameRef === 'long' ) {
					zoomer_long = true;
					
					if( $('.jMyCarousel .long').length === 0 ) {
						$('.jMyCarousel').addClass('padTop57');
					}
					
					if( !productMagnifiedContainer.hasClass('tall') ) {
						productMagnifiedContainer.addClass('tall');
					}
					launchLongZoom();
				}
				// ==== end of switching templates ==== //
				
				$('#worndiv').html('');
				$('#worndiv').html(data);
				if (ie) {
					$('#worndiv > h2 img').hide();
				}
				var count = $('#worndiv div img').length;
				if( count === 0 ) {
					$('#wrapper_product_image').addClass('centered');
					
					$('flash_zoom').addClass('centered_pa');//flash zoom
					//$('.btn_zoom_block a').addClass('shifted_left_309');//flash zoom
				}
				else if ( count > 0 ) {
					$('#wrapper_product_image').removeClass('centered');
					
					$('flash_zoom').removeClass('centered_pa');//flash zoom
					//$('.btn_zoom_block a').removeClass('shifted_left_309');//flash zoom
				}
				
				$('#worndiv div img').load(function(){
					count--;
					if (!count) {
						$('#worndiv').fadeIn(800, function(){
							if (ie) {
								$('#worndiv > h2 img').show();
							}
						});
					}
			   });
			});
			$.post('/lib.php?mode=productdetail&md=2&prid='+id, function(data){
				$('#maindiv').html(data).fadeIn(800);
			});
			$.post('/lib.php?mode=productdetail&md=3&prid='+id, function(data){
				$('#alternatediv').html(data);
				$('#alternatediv div img').load(function(){
					$('#alternatediv').fadeIn(800);
			   });
			});
			
			var time = 700;
			$('.col').css({'z-index' : 900});
			$('.col').animate({opacity:1}, time, function(){
				$('.descript, .alternate_view, .product_action, .price').animate({opacity:1}, time);
				if (zoomer_long) {
					if ( (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPhone/i)) ){
						launchLongZoom();
					}
					else {
						long_retina_click();
						long_retina_click();
					}
				}
				else {
					if ( (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPhone/i)) ){
						launchStandartZoom();
					}
					else {
						standart_retina_click();
						standart_retina_click();
					}
				}
			});
		}, 600);
	});
	
	
}

function view_alternate(first_primary_small, first_primary_large, first_alternate_small, first_alternate_large) {
	var altimage = document.getElementById("altimage");
	var bigimage = document.getElementById("bigimage");
	var retina = document.getElementById("retina");
	var time = 200;
	if (bigimage.src != "http://207.150.204.150/photos/shop/"+first_primary_large && bigimage.src != "http://207.150.204.150/photos/shop/"+first_alternate_large) {
		bigimage.src = "http://207.150.204.150/photos/shop/"+first_primary_large;
	}
	if( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) ) {
		if(bigimage.src=="http://207.150.204.150/photos/shop/"+first_primary_large) {	
			$('#altimage, #bigimage').animate({'opacity' : '0'}, time, function(){
				bigimage.src = "http://207.150.204.150/photos/shop/"+first_alternate_large;
				altimage.src = "http://207.150.204.150/photos/shop/"+first_primary_small;
				retina.style.background = "url("+"http://207.150.204.150/photos/shop/"+first_alternate_large+") no-repeat";
				$('#bigimage').load(function(){
					$('#altimage, #bigimage').animate({'opacity' : '1'}, time);
				});
			});	
	   } else {
			$('#altimage, #bigimage').animate({'opacity' : '0'}, time, function(){
				bigimage.src = "http://207.150.204.150/photos/shop/"+first_primary_large;
				altimage.src = "http://207.150.204.150/photos/shop/"+first_alternate_small;	
				retina.style.background = "url("+"207.150.204.150/photos/shop/"+first_primary_large+") no-repeat";
				$('#altimage, #bigimage').animate({'opacity' : '1'}, time);
			});
	   };
	}
	else if (bigimage.src=="http://207.150.204.150/photos/shop/"+first_primary_large) {
		$('#alternatediv #altimage').fadeOut(600);
		$('.flash_zoom').fadeOut(600, function(){
			flash_width = $('.flash_zoom #zoomer').width();
			flash_height = $('.flash_zoom #zoomer').height();
			$('.flash_zoom').html('<div id="flash_zoom_obj"><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
			var flashvars = {
				W: flash_width,
				H: flash_height,
				urlImage: 'photos/shop/'+first_alternate_large
			};
			var params = {
				menu: "false",
				wmode: "transparent",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				bgcolor: "#EBEBED"
			};
			var attributes = {
				id:"zoomer"
			};
			swfobject.embedSWF("templates/deluxe/flash/zoom.swf", "flash_zoom_obj", flash_width, flash_height, "10.0.0", "templates/deluxe/flash/expressInstall.swf", flashvars, params, attributes);
			altimage.src = "http://207.150.204.150/photos/shop/"+first_primary_small;
			bigimage.src = "http://207.150.204.150/photos/shop/"+first_alternate_large;
			$('.flash_zoom, #alternatediv #altimage').fadeIn(600);
		});		
	} 
	else {
		$('#alternatediv #altimage').fadeOut(600);
		$('.flash_zoom').fadeOut(600, function(){
			flash_width = $('.flash_zoom #zoomer').width();
			flash_height = $('.flash_zoom #zoomer').height();
			$('.flash_zoom').html('<div id="flash_zoom_obj"><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
			var flashvars = {
				W: flash_width,
				H: flash_height,
				urlImage: 'photos/shop/'+first_primary_large
			};
			var params = {
				menu: "false",
				wmode: "transparent",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				bgcolor: "#EBEBED"
			};
			var attributes = {
				id:"zoomer"
			};
			swfobject.embedSWF("templates/deluxe/flash/zoom.swf", "flash_zoom_obj", flash_width, flash_height, "10.0.0", "templates/deluxe/flash/expressInstall.swf", flashvars, params, attributes);
			altimage.src = "http://207.150.204.150/photos/shop/"+first_alternate_small;
			bigimage.src = "http://207.150.204.150/photos/shop/"+first_primary_large;
			$('.flash_zoom, #alternatediv #altimage').fadeIn(600);
		});		
	}
}


var executed = true;

function show_press(id,tabnum) {
	if (!executed) {
		return false;
	}
	executed = false;
	var fade_time = 200;
	$('#pressdiv1'+tabnum+', #pressdiv2'+tabnum).animate({opacity:0}, fade_time);
	$('#pressdiv4'+tabnum).animate({opacity:0}, fade_time, function(){
		$('.ajax-loading').css({opacity:1});			
		$.post('lib.php?mode=showpress&id='+id+'&md=1&tabnum='+tabnum,
				function(data)
				{
					document.getElementById("pressdiv1"+tabnum).innerHTML = data; 

					$.post('lib.php?mode=showpress&id='+id+'&md=2&tabnum='+tabnum,
		   
					 function(data)
					 {
						 document.getElementById("pressdiv2"+tabnum).innerHTML = data; 

						 $.post('lib.php?mode=showpress&id='+id+'&md=3&tabnum='+tabnum,
				
						  function(data)
						  {						  
							  if (data.indexOf('</a>') != -1 && 
								$(data).attr('href') != '' && 
								$(data).html() != '') {
									$("#pressdiv3"+tabnum).attr('href', $(data).attr('href')).html('<span>' + $(data).html() + '</span>');
									$('#pressdiv3'+tabnum).fadeIn(200);
							  }
							  else if (data.indexOf('.pdf') != -1) {
									document.getElementById("pressdiv3"+tabnum).href = data;
								    $('#pressdiv3'+tabnum).html('<img alt="PDF" src="templates/deluxe/img/icon_pdf.png">').fadeIn(200);
                                }
							  else {
                                    $('#pressdiv3'+tabnum).fadeOut(200);
                                }

							  $.post('lib.php?mode=showpress&id='+id+'&md=4&tabnum='+tabnum,
					 
							   function(data)
							   {
									document.getElementById("pressdiv4"+tabnum).innerHTML = data;
									$('#pressdiv4').waitForImages( {
											finished:function() {
												$('.ajax-loading').css({opacity:0});
												$('#pressdiv1'+tabnum+', #pressdiv2'+tabnum+', #pressdiv4'+tabnum).animate({opacity:1}, fade_time, function(){
													setTimeout(function(){executed = true;}, 500);
												});
											},
											waitForAll:true	
										}
									);
							   }
							  );
						  }
				
						 );
					 }
					);
				}
			   );
	});
}

function update_shop(){
	$('#cartact').val('updatecart');
	$('form#cartform').trigger("submit");
};

//var is_end_anim = true;
//function changeStyleImage(newSrc, type) {
//	var IE='\v'=='v';
//	$('.img-full_set').fadeOut();
//	//if (IE && is_end_anim){
//		//$('.ip > img:first').fadeOut(function(){$(this).css('display', 'none')});
//	//}
//	//else if( newSrc !== $('.ip > img:first').attr('src') && is_end_anim ) {
//	//else if( is_end_anim ) {
//	if( is_end_anim === true ) {
//		is_end_anim = false;
//		$('.ip > img:first').fadeOut(function() {
//			$('.ip > img:first').attr('src', '');
//			$('.ip > img:first').attr('src', newSrc).removeClass('standart long').addClass(type);
//			setTimeout(function() {
//				$('.ip > img:first').fadeIn(function(){is_end_anim = true;});	
//			}, 200 );
//		});
//	};
//};
//
//var is_end_anim2 = true;
//function hideProductImage() {
//	if( is_end_anim2 === true ) {
//		is_end_anim2 = false;
//		$('.ip > img:first').fadeOut( function() {
//			$('.img-full_set').fadeIn( function() {
//				is_end_anim2 = true;
//			} );
//		} );
//	}	
//}

//mouseover
function changeStyleImage(newSrc, type) {
	
	
	
         $('.img-full_set').stop(true,true).fadeOut();
  
	
		if($('.ip > img:first').is(':animated')) {
           $('.ip > img:first').stop(true,true).attr('src', '').attr('src', newSrc).removeClass('standart long').addClass(type).fadeIn();
        }else{
		   $('.ip > img:first').fadeOut(function() {
		   	  $('.ip > img:first').attr('src', '').attr('src', newSrc).removeClass('standart long').addClass(type).fadeIn();
		   });
	    };
		
		
	
};


//mouseout

function hideProductImage() {


		$('.ip > img:first').stop(true,true).fadeOut();
		$('.img-full_set').stop(true,true).fadeIn();
	
	

}

/*New things page BEGIN*/
function show_detailsIpad(id, elem) {
	window.location.hash = '/' + id;
	var classNameRef = $(elem).attr('class'),
		productMagnifiedContainer = $('.col.ip');
	$.post('/lib.php?mode=productdetail&md=1&prid='+id, function(data){
		$('#bigimage').fadeOut(600);
		$('.btn_zoom_block a').css( { 'zIndex':'10','display':'block' } );
		$('#maindiv').fadeOut(600, function(){
			$('#bigimage').filter('#bigimage').attr('src','').attr('src',data);
			$('#retina').css('background-image', 'url('+data+')');
			$('.ajax-loader-zoom').animate({'opacity':'1'}, 100);
		});
		setTimeout(function(){
				$('#worndiv').html('');
				$('#bigimage').load(function(){
					$('.ajax-loader-zoom').animate({'opacity':'0'}, 100);
					setTimeout( function() {
						$('#bigimage').fadeIn(800);
					}, 300 ); 	
				});
			// switch between long and standard templates when clicking on product in the scroll
			if( classNameRef === 'standard' ) {
				zoomer_long = false;
				if( productMagnifiedContainer.hasClass('tall') ) {
					productMagnifiedContainer.removeClass('tall');
				}
				launchStandartZoom();
			}
			else if( classNameRef === 'long' ) {
				zoomer_long = true;
				if( !productMagnifiedContainer.hasClass('tall') ) {
					productMagnifiedContainer.addClass('tall');
				}
				launchLongZoom();
			}
			// ==== end of switching templates ==== //
			$.post('/lib.php?mode=productdetail&md=2&prid='+id, function(data){
				$('#maindiv').html(data).fadeIn(800);
			});
			var time = 700;
			$('.col').css({'z-index' : 900});
			$('.col').animate({opacity:1}, time, function(){
				$('.descript, .product_action, .price').animate({opacity:1}, time);
				if ($('.col.ip').hasClass('tall')) {
					launchLongZoom();
				}
				else {
					launchStandartZoom();
				}
			});
		}, 600);
	});
}

/* new things thumbs rollover -> BEGIN */
if( document.location.href.indexOf('New_things') !== -1 ) {
	$(document).ready( function(){
		$('.new_things_page .cw. img').eq(0).addClass('new_things_active');
		$('.new_things_page .cw. img').not( $('.new_things_active') ).css({ 'opacity':'0.7' });
		$('.new_things_page .cw. img').click( function(){
			$('.new_things_page .cw. img').css({ 'opacity':'0.7' }).removeClass('new_things_active');
			$(this).css({ 'opacity':'1' }).addClass('new_things_active');
		} );

		var timeout0;
		$('.new_things_page .cw. img').hover( function(){
			clearTimeout( timeout0 );
			$(this).css({ 'opacity':'1' });
			$('.new_things_page .cw. img').not( $(this) ).css({ 'opacity':'0.7' });
		}, function(){ 
			$('.new_things_page .cw. img').not($('.new_things_active')).css({ 'opacity':'0.7' });
			timeout0 = setTimeout( function(){
				$('.new_things_active').css({ 'opacity':'1' });
			}, 300 ); 
		} );
	} );
}
/* new things thumbs rollover <- END */
/*New things page END*/

$(document).ready(function() {
	
	if($('.pdf_link').text() != ''){
		$('.pdf_link').fadeIn(0);
	}

	
	document.getElementById('main').onkeypress = function() {
		if (window.event && window.event.keyCode == '13' && $('input:focus').length == 0) {
			window.event.cancelBubble = true;
			return false;
		}
	}
});

//toggle visibility of credit card back popup
if( location.href.indexOf('xlspg=cart') !== -1 ) {
	$( document ).ready( function() {
		$('.whats_this').click( function(e) {
			e.preventDefault();
			$('.popup-credit-card-back').removeClass('popup-credit-card-back-hidden');	
		} );
		
		$('.popup-credit-card-back a').click( function(e) {
			e.preventDefault();
			$('.popup-credit-card-back').addClass('popup-credit-card-back-hidden');
		} );
	} );
}


