function setCountry(){
	 /*
	$("select[@name='country']").change(function () {
		var lingua = $("select[@name='country']").val();
		document.location.href = BASE_URL + lingua;
	})
	 */	
 
	$('.chose_country').click( function() {
			
		if($('#bandiere').css('display') == 'none'){
			$('#bandiere').slideDown();	
		}else{
			$('#bandiere').slideUp();
		}
			
	});
 
 $(".js_img_country").click( function() {							  
		var lingua = $(this).attr('alt');
		document.location.href = BASE_URL + lingua;
	
	});
 
}

function set_accordion(){

	
	$('.js_accordion').click( function() {
		doAccordion(this);
		
		
		/*var accordion = $(this).parent().next().next();
		if (accordion.css("display") == 'none'){
			$(this).removeClass('freccia_dx');
			$(this).addClass('freccia_bottom');
			accordion.slideDown();
		}else if (accordion.css("display") == 'block'){
			$(this).removeClass('freccia_bottom');
			$(this).addClass('freccia_dx');
			accordion.slideUp();
		}		   
		*/
	});
	
}

function doAccordion(elemento){

	var accordion = $(elemento).parent().next().next();
	if (accordion.css("display") == 'none'){
		$(elemento).removeClass('freccia_dx');
		$(elemento).addClass('freccia_bottom');
		accordion.slideDown();
	}else if (accordion.css("display") == 'block'){
		$(elemento).removeClass('freccia_bottom');
		$(elemento).addClass('freccia_dx');
		accordion.slideUp();
	}
	
}
function doAllAccordion(){
	$('.js_accordion').each(function (i) {
			doAccordion(this);
	});			

}

function setBack(){
	$('.js_btn_back').click( function() {
		history.back();		
	});
	
}


function set_gallery(){
	
	$('.js_thumb_gallery').click( function() { 								   
		var id = "#"+$(this).attr('id');
		var src = $(id +">img").attr('class');
		$('#js_foto_content').hide();
		$('#js_foto_content>img').attr('src', src);
		$('#js_foto_content').fadeIn();
	});
	
}
function set_photo_gallery(){
	
	$('.js_thumb_gallery').click( function() { 								   
		var id = "#"+$(this).attr('id');
		var src = $(id +">img").attr('class');
		var testo = $(id +">img").attr('alt');
		$('#js_foto_content').hide();
		$('#js_foto_content>img').attr('src', src);
		$('#js_foto_titolo').html(testo);
		$('#js_foto_content').fadeIn();
	});
	
}

function move_thumb(direction) {				
				
	var margin_left = $('#thumb_content').css('marginLeft');
	margin_left = parseInt(margin_left.slice(0,margin_left.length-2));
			
	switch (direction) {
		case 'dx':
			if ((thumb_content_width + margin_left) > $('#gallery').width()) {		//sommo perchè il margin left è un valore negativo							
				if (anima) return;
				anima = true;
				margin_left -= step;
				$("#thumb_content").animate( { marginLeft : margin_left }, "normal", unlock_animation );
			}
			break;
		
		case 'sx':
			if (margin_left < 0) {
				if (anima) return;
				anima = true;
				margin_left += step;
				$("#thumb_content").animate( { marginLeft : margin_left }, "normal", unlock_animation );
			}
			break;
	}
	
}

function unlock_animation() {

	anima = false;

}

function set_FTP_AREA(){
	$('.js_btn_ftp').click( function() { 
		var username = $('#form_ftp_username').val();
		var password = $('#form_ftp_password').val();
		
		if(username != '' && password != ''){
			var url = 'ftp://'+username+':'+password+'@ftp.altayscientific.com';
			window.open(url);
			
		}else{
			chiamaBlockUI(LABEL_ERRORE, LABEL_ERRORE_VALIDATE_FTP);
			return false;
		}

	});
}

function chiamaBlockUI(titolo, testo) {
	
	
	
	
	var str;
	str = '<div style=" position:relative;"><div class="testo"></div><br />';
	str += '<div class="testo"><p class="titolo">'+titolo+'</p>';
	str += '<p>'+testo+'</p></div>';
	
	str = str + '<div><span id="chiudi_blockui" class="btn testo" >'+LABEL_CHIUDI+'</span><br /><br /></div></div>';
	
	$.blockUI({ 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			color: '#C7C7C7',
			cursor: 'default',
			margin:'auto',
			top: '200px',
			width: '28%'			
		},

		message: str,
		overlayCSS: {
			cursor: 'default',
			backgroundColor:'#000', 
			opacity:'0.8' 
			/*sfondo*/
		}
	});
	
	$("#chiudi_blockui").click(function() {									 				
		$.unblockUI();			
	});
}


function set_search(){

	$('.js_search').click( function() {
		apply_search();
	});
	
	$(window).keydown(function(event){
		if(event.keyCode == 13){
			apply_search()
		}					   
	});
	
}

function apply_search(){
	var my_search = $("input[@name='search']").val(); 
	if(my_search != ''){
		document.location.href = URL_SEARCH + '/'+my_search;
	}
}
