
$(function() {
	//$(".brand_view").colorbox({width:"600px", height:"700px", iframe:true});	
	
	$('.continue').click(function() {
		id = $(this).attr('data');
		$(this).hide();
		$('#loading'+id).show();
		if(id==3){
			$_shipping = $('input[name=shipping]:checked').val();
			$.post("/checkout", { section: id, shipping: $_shipping },
			function(data) {
				$('.total span.jsonShipping').text(data.shipping);
				$('.total span.jsonGrandTotal').text(data.grand_total);
				$('#amount').val(data.grand_total_amount);
				$('#section-'+(id-1)).hide();
				$('#section-'+id).show();
			},"json");

		}else{
			$('#section-'+(id-1)).hide();
			$('#section-'+id).show();
		}
		$(this).parent().parent().parent().parent().children().children('span+span').attr('data', (id-1)).show();
		$(this).parent().parent().parent().parent().children('div.column').css('background-color','#f1fff1');
		
	});
	$('.edit').click(function() {
		id = $(this).attr('data');
		if(id){
			$('span.edit').each(function(index) {
				divIndex = index+1;
				if(id>divIndex){
					$(this).show();
				}else{
					$(this).hide();
					$(this).parent().css('background-color','#ffffff');
				}	
				$('.loading').hide();
				$('.continue').show();
			});
			$('#section-1, #section-2, #section-3, #section-4').hide();
			$('#section-'+id).show();
		}
	});
	
	$('.register-new-user').click(function() {
		$('#section-0').hide();
		$('#section-1').show();
	});
	
	
	
	$(".slider").scrollable();
	
	$(" #mainNav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(200);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	$(".look_item").hover(
       function() {
		  gap = 600 - ($(this).children().children('.look_box').height()); 
		  $(this).children().children('.look_box').css('marginTop', gap+'px');
          $(this).children().children('.img').stop(true, false).fadeTo('fast', 0.6);
		  $(this).children().children('.look_box').stop(true, false).fadeTo('fast', 0.6);
		  
		  //url = $('#'+this.id).attr('data');
		  //$('#fb'+this.id).html('<iframe src="http://www.facebook.com/plugins/like.php?href='+url+'&amp;send=false&amp;layout=button_count&amp;width=60&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60px; height:21px;" allowTransparency="true"></iframe>');
		  
		  
       }, function() {
          $(this).children().children('.img').stop(true, false).fadeTo('medium', 1.0);
		  $(this).children().children('.look_box').stop(true, false).fadeTo('fast', 0.0);
       }
    );
	$(".press_item").hover(
       function() {
		  gap = 600 - ($(this).children().children('.press_box').height()); 
		  $(this).children().children('.press_box').css('marginTop', gap+'px');
          $(this).children().children('.img').stop(true, false).fadeTo('fast', 0.6);
		  $(this).children().children('.press_box').stop(true, false).fadeTo('fast', 0.6);
       }, function() {
          $(this).children().children('.img').stop(true, false).fadeTo('medium', 1.0);
		  $(this).children().children('.press_box').stop(true, false).fadeTo('fast', 0.0);
       }
    );	
	
	$.fn.supersized.options = {  
		startwidth: 1500,  
		startheight: 1000,
		minsize: .50,
		slideshow: 0,
		slideinterval: 5000,
		navigation: 0
	};
	$('#supersize').supersized(); 
	
	
	
		
});
/*
$().ready(function () {
	$('#productNav').vScroll({ speed: 500, upID: "#prevButton", downID: "#nextButton" });
});
*/
function cc_submit(f){
	fo = Array(f.creditCardName, f.cardNum, f.CardSecurityCode);
	for(i=0; i<fo.length; i++){
		if(fo[i].value == ''){ 
			$('#f_'+$(fo[i]).attr('id')).css('border', '1px solid #ff0000'); 
			$('#i_'+$(fo[i]).attr('id')).show();
			$("input[id=\'"+$(fo[i]).attr('id')+"\']").focus();
			return false;
		}
		$('#f_'+$(fo[i]).attr('id')).css('border', '1px solid #DBDBDB');
		$('#i_'+$(fo[i]).attr('id')).hide();
	}
	
	if(validateCreditCard(fo[1].value) == false){
		$('#f_'+$(fo[1]).attr('id')).css('border', '1px solid #ff0000');
		$('#i_'+$(fo[1]).attr('id')).show();
		return false;	
	}
	$('.submit_btn').hide(); $('.submit_loading').show(); 
}
function validateCreditCard(s) {
    var v = "0123456789";
    var w = "";
    for (i=0; i < s.length; i++) {
        x = s.charAt(i);
        if (v.indexOf(x,0) != -1)
        w += x;
    }
    j = w.length / 2;
    k = Math.floor(j);
    m = Math.ceil(j) - k;
    c = 0;
    for (i=0; i<k; i++) {
        a = w.charAt(i*2+m) * 2;
        c += a > 9 ? Math.floor(a/10 + a%10) : a;
    }
    for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
    return (c%10 == 0);
}
function val(f,n){
	if(f.value == n) f.value = '';	
}
function fill(f,n){
	if(f.value == '') f.value = n;
}
function check(f){
	fo = Array(f.name, f.email);
	v = Array('Your name','Email address');
	for(i=0; i<fo.length; i++){
		if(fo[i].value == v[i]){
			$('#fo_'+$(fo[i]).attr('id')).css('background-color', '#8E1414'); 
			return false;
		}
		$('#fo_'+$(fo[i]).attr('id')).css('background-color', '#141414'); 
	}

	em = f.email.value;
	AtPos = em.indexOf("@")
	StopPos = em.lastIndexOf(".")
	
	if (AtPos == -1 || StopPos == -1) {
		$('#fo_'+$(fo[1]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}else if (StopPos < AtPos) {
		$('#fo_'+$(fo[1]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}else if (StopPos - AtPos == 1) {
		$('#fo_'+$(fo[1]).attr('id')).css('background-color', '#8E1414'); 
		return false;
	}
	if($('#uf1').val() == ''){
		$('#fo_'+$('#uf1').attr('id')).css('background-color', '#8E1414'); 
		return false;	
	}
	//$('.sbmt').hide();
	//$('.load').show();
}

function check_size(f){
	if(f.s_size.value){
		return true;
	}else{
		$('.select').slideDown(200);
		return false;
	}
}

function copy_address(f){
	var billing = new Array(f.address,f.phone,f.fax,f.country,f.state,f.city,f.zip);
	var shipping = new Array(f.Saddress,f.Sphone,f.Sfax,f.Scountry,f.Sstate,f.Scity,f.Szip);
	
	if($('#copyAddress').is(':checked')){
		$('.shippingInfo').fadeIn();
		/*
		for(x=f.Dcountry.options.length-1;x>=0;x--){
			if(f.Dcountry.options[x].selected)
			f.country.options[x].selected=true;
		}
		*/
		//$("#hide_show").hide();

	}else{
		$('.shippingInfo').fadeOut();
	}
}




