// JavaScript Document
$(document).ready(function() {
		$('div .modslide a').click(function(){
			//$('.box_prodotto_prima_categoria').hide();
			var id = this.getAttribute("id");
			var control = $('#img'+id+'').attr('name');
			if(control == 'arr_dx' ){
				$('#img'+id+'').attr('name','arr_down');
				$('#img'+id+'').attr('src','../_img/arw_viola_down.jpg');
				$('#box'+id+'').slideToggle('normal');
			}else{
				$('#img'+id+'').attr('name','arr_dx');
				$('#img'+id+'').attr('src','../_img/arw_viola.jpg');
				$('#box'+id+'').slideToggle('normal');
			}
			
		});
		
		$('div .modslideteam a').click(function(){
			//$('.box_prodotto_prima_categoria').hide();
			var id = this.getAttribute("id");
			var control = $('#img'+id+'').attr('name');
			if(control == 'arr_dx' ){
				$('#img'+id+'').attr('name','arr_down');
				$('#img'+id+'').attr('src','../_img/arw_viola_down.jpg');
				$('#box'+id+'').slideToggle('normal');
			}else{
				$('#img'+id+'').attr('name','arr_dx');
				$('#img'+id+'').attr('src','../_img/arw_viola.jpg');
				$('#box'+id+'').slideToggle('normal');
			}
			
		});
													  
});

	
function changeIMG(folder,id){
	//window.clearTimeout(tim);
	//nameImg = $("#mycarousel").attr("title");
	//nome = $(this).attr("id");
	var nomeOld = $("#wrapIMG").attr("name");
	var colorOld = $("#wrapIMG").attr("color");
	var sizeOld = $("#wrapIMG").attr("size");
	var codeOld = $("#wrapIMG").attr("code");
	
	
	var nome = $('#'+id+'').attr("name");
	var color = $('#'+id+' > img').attr("color");
	var size = $('#'+id+' > img').attr("size");
	var code = $('#'+id+' > img').attr("code");
	
	//alert(color+"-"+size+"-"+code);
	//alert(colorOld+"-"+sizeOld+"-"+codeOld);
	$("#wrapIMG").fadeOut(1000, function () {	});
	
	$("#wrapIMG").attr("src", "../phpThumb/phpThumb.php?src=../_img/"+folder+"/"+nome+"&w=430&h=485&fltr[]=usm|80|0.5|3");	
	$("#wrapIMG").fadeIn(1000, function(){	
			$("#wrapLink").attr("href", "../_img/"+folder+"/"+nome+"");
			$("#zoomLink").attr("href", "../_img/"+folder+"/"+nome+"");
			$("#wrapIMG").attr("name", ""+nome+"");
			$("#wrapIMG").attr("color", ""+color+"");
			$("#wrapIMG").attr("size", ""+size+"");
			$("#wrapIMG").attr("code", ""+code+"");
			$('#color').html("Color "+color+"");
			$('#size').html("Sizing "+size+"");
			$('#code').html("Code "+code+"");
			$('#'+id+' > img').attr("src", "../phpThumb/phpThumb.php?src=../_img/"+folder+"/"+nomeOld+"&w=133&h=150&fltr[]=usm|80|0.5|3");		
			$('#'+id+' > img').attr("color",""+colorOld+"");
			$('#'+id+' > img').attr("size",""+sizeOld+"");
			$('#'+id+' > img').attr("code",""+codeOld+"");
			$('#'+id+' > span').html(colorOld);
			$('#'+id+'').attr("name",""+nomeOld+"");
			if(folder == "boots"){ changeBoot(code); };
			if(folder == "bindings"){ changeBindings(code); };
			if(folder == "boards"){ changeBoards(size); };
	});
	
}

function changeBoot(code){
	if(code){
		$.ajax({
		   type: "POST",
		   url: "_inc_checkBootsugg.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
						$('#sugg').html(""+msg+"");							
						
				   }
			});
		$.ajax({
		   type: "POST",
		   url: "_inc_checkBootbuyonline.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
			   			if(msg){
							$('#buyonline').removeClass('none');
							$('div#box2').html(""+msg+"");	
						}else{
							$('#buyonline').addClass('none');
						}
				   }
			});
		
	}else{
	}
}

function changeBindings(code){	
	if(code){
		$.ajax({
		   type: "POST",
		   url: "_inc_checkBindingsugg.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
						$('#sugg').html(""+msg+"");							
						
				   }
			});
		$.ajax({
		   type: "POST",
		   url: "_inc_checkBindingbuyonline.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
			   			if(msg){
							$('#buyonline').removeClass('none');
							$('div#box2').html(""+msg+"");	
						}else{
							$('#buyonline').addClass('none');
						}
				   }
			});
		
	}else{
	}
}


function changeBoards(code){
	if(code){
		$.ajax({
		   type: "POST",
		   url: "_inc_checkBoardsugg.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
			  // alert(msg);
						$('#sugg').html(""+msg+"");							
						
				   }
			});
		/*$.ajax({
		   type: "POST",
		   url: "_inc_checkBindingbuyonline.php",
		   data: "code="+code+"",
		   //Evento di riuscita
		   success: function(msg){
			   			if(msg){
							$('#buyonline').removeClass('none');
							$('div#box2').html(""+msg+"");	
						}else{
							$('#buyonline').addClass('none');
						}
				   }
			});*/
		
	}else{
	}

}

function findRegion(country){
	if(country){
		
		$.ajax({
		   type: "POST",
		   url: "_inc_findRegion.php",
		   data: "country="+country+"",
		 
		   //Evento di riuscita
		   success: function(msg){
						$('#Region').html(""+msg+"");
						$('#Province').html("");
				   }
			});
	}
}

function findProvince(region){
	if(region){
		
		$.ajax({
		   type: "POST",
		   url: "_inc_findProvince.php",
		   data: "region="+region+"",
		 
		   //Evento di riuscita
		   success: function(msg){
			   			
						$('#Province').html(""+msg+"");		
				   }
			});
	}
}


function findResults(state,country){
	
	if(country){
		if(country == 1){ $('#titlepage').html("DEALERS USA");};
		if(country == 2){ $('#titlepage').html("DEALERS ITALIA");};
		if(country == 3){ $('#titlepage').html("DEALERS CANADA");};
		if(country == 4){ $('#titlepage').html("DISTRIBUTORS");};
		$.ajax({
		   type: "POST",
		   url: "_inc_findResults.php",
		   data: "country="+country+"&state="+state+"",
		   //Evento di riuscita
		   success: function(msg){
						$('#Results').html(""+msg+"");							
						
				   }
			});
	}
}


function check() {
	var validate_token = $('#verifica').attr("value");
	var token = $('#Token').attr("value");
	$.ajax({
		 type: "POST",
		 url: "_captchaControl.php",
		 data: "validate_token="+validate_token+"&token="+token+"",
	    //Evento di riuscita
		 success: function(msg){
			if(msg == '1' ){
				$('#formo').submit();
			 }else{
				alert('Verifica non corretta.');
			 }				   
		}
	});	
}