// SWAP IMAGES FUNCTIONS

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var reNumbers = /^[0-9]*$/;

function only_numbers(string){
   return reNumbers.test(string);
}

var twoWords = /^.+\s+.+$/;

function has_two_words(string){
   return twoWords.test(string);
}

var reEmail = /^[a-zA-Z\-\_\.0-9]+\@[a-zA-Z\-\_\.0-9]+[a-zA-Z0-9]\.[a-zA-Z]{2,3}$/;

function is_email(string){
   return reEmail.test(string);
}

var reNumbers1 = /^[^0-9]+$/;

function no_numbers(string){
   return reNumbers1.test(string);
}

function toogle_display_class(element, last, new_class, old_class, key_item, key_class){
	if(key_item==null) key_item='item';
	if(key_class==null) key_class='class';
	for (var i = 0; i <= last; i++){
		if(i==element){
			$("#"+key_class+i).removeClass(old_class);
			$("#"+key_class+i).addClass(new_class);
						
		}
		else{
			$("#"+key_class+i).removeClass(new_class);
			$("#"+key_class+i).addClass(old_class);			
		}

		$("#"+key_item+i).hide();
	}
	$("#"+key_item+element).show();
}

function cart_quantity(id, step){
	valor = parseInt($("#qt_"+id).val())+step;
	if(valor<0) valor = 0;
	if(valor>99) valor = 99;
	$("#qt_"+id).val(valor);
	document.cart_form.submit();
}

function toogle(element){
	$(element).toggle();
}

function show(element){
	$(element).show();
}

function hide(element){
	$(element).hide();
}

var global_step=0;


function switch_icn_likes(){
	if($("#img_likes").attr("src") == "/images/icn_likes_on.gif"){
		$("#img_likes").attr("src", "/images/icn_likes.gif");
	}
	else{
		$("#img_likes").attr("src", "/images/icn_likes_on.gif")
	}
}

function like(type, id){
	$.get("/ax_like.php", {type: type, ref_id: id},
		function(data){
			if(data!='') $("#nr_likes").html(data);	
	});
	return false;
}


function chp_photo(element, img_path, img_width, img_height, big_path, big_width, big_height){
	$(".photos .item").removeClass("item_sel");
	$("#"+element).addClass("item_sel");
	
	data="";
	if(big_width>500 && big_height>500){
		data = data + "<a id=\"prod_photo_url\" href=\""+big_path+"\" class=\"cloud-zoom\" title=\"\" rel=\"adjustX: 15, adjustY:0, zoomWidth:510,zoomHeight:400,showTitle:false,smoothMove:1\" name=\"Image\">";
	}
	data = data + "<img src=\""+img_path+"\" width=\""+img_width+"\" height=\""+img_height+"\" alt=\"\" title=\"\" border=\"0\"/>";
	if(big_width>500 && big_height>500) data = data + "</a>";
	
	$(".img_prod").html(data);
		
	if(big_width>500 && big_height>500){
		hide("#test2");
		show("#test1");
 		$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();	
	}	
	else{
		hide("#test1");
		show("#test2");
	}
}

function ins_comment(type, ref_id){
	var cm_text = $("#comm_text").val();
	var cm_name = $("#comm_name").val();
	var cm_email = $("#comm_email").val();
	
	$.get("/ax_ins_comment.php", {type: type, ref_id: ref_id, cm_name: cm_name, cm_email: cm_email, cm_text: cm_text},
		function(data){
			$("#ins_comm").html(data);	
	});
	return false;
}

function cycle_zone1(count){
	setTimeout(function() {
		
	}, 2000);
}


function show_icon()
{
$('.search_icon').css('visibility','visible');
}
function hide_icon()
{
$('.search_icon').css('visibility','hidden');
}

function toggle_value(value)
{
	if($('#search_string').val()==value)
	{
	  $('#search_string').val('');
	  show_icon();
	}
	else if($('#search_string').val()!=value)
	{
		if($('#search_string').val()=='')
		{
		$('#search_string').val(value);
		hide_icon();
		}
	}
}
function img_chgover(img_class)
{
    $('.'+ img_class)
        .mouseover(function() { 
            var src = $(this).attr("src").match(/[^\.]+/) + "_over.png";
            $(this).attr("src", src);
        })
        .mouseout(function() {
            var src = $(this).attr("src").replace("_over", "");
            $(this).attr("src", src);
        });

}

$(function() {
    $(".zone1_items").jCarouselLite({
        btnNext: "#arr_r",
        btnPrev: "#arr_l"
      });
});

function change_prod_qty(id,value,price)
{
	var new_value= parseInt($('#'+id).val()) + parseInt(value);
	if(new_value > 0)
	{
   $('#'+id).val(new_value);
   var new_price = new_value * price;
   $('.total_prod').html('total: &euro; ' + (parseFloat(new_price / 100)+"").replace(".",","));
	}
	
}
function refresh_cart2(prod_option_id){
	var qty = $('#qt_prod').val();
	
	
	$.get("/ax_refresh_cart.php", {prod_option_id: prod_option_id, qtde : qty},
		function(data){
			$(".hd_cart").html(data);
			$.scrollTo( '#top_page', 800 );
			});
		
		
	    $('#notification')
        .jnotifyInizialize({
            oneAtTime: false,
            appendType: 'append'
        });

	$.get("/ax_get_prod.php", {prod_option_id: prod_option_id},
		function(data){
       $('#notification').show();
       $('#notification').jnotifyAddMessage({
            text: data,
            permanent: false

       	 });
       	

		});
	
}

function selected_link(id)
{
 	$(id).css('color','#FFF');
 	
}

function unselected_link(id)
{
	 $(id + ':hover').css('color','#FFF');
	 $(id).css('color','#CCC');
}

function align_page(margin)
{
	 $('.page').css('margin-top', margin + 'px');
}

function redim_page()
{
	var height=0;
	var otherheight = 0;
	var finalheight=0;
	var pageheight=0;
			
	height=$('body').innerHeight();
	pageheight= $('.page').height();
	pagespecialheight= $('.page_special').height();
	otherheight= $('.top_footer').outerHeight()  + 42 + $('.top_header').outerHeight()  + $('.bottom_header_wb').outerHeight();
	finalheight = height - (otherheight +  60);
	if (pageheight < finalheight) 
	{
		$('.page').css("height", finalheight + 'px');
		if((pagespecialheight < finalheight))
		{
			$('.page_special').css("height", finalheight + 'px');
		}
	}
}

function buying_popup()
{
 $('#pop').bPopup({closeClass:'pop_close',zIndex:'10000'});
	
}
function size_guide_popup()
{
 $('#size_pop').bPopup({closeClass:'size_pop_close',zIndex:'10000'});
	
}

function get_stores(city_id)
{
	$.get("/ax_get_stores.php", {id: city_id},
		function(data)
		{
			var info = data.split('@@');
			
			$('#lojas_box').html(info[0]);
			$('#city_choosed').html(info[1]);
		});

		$.get("/ax_get_map.php", {city_id: city_id},
		function(mapa)
		{
			var info = mapa.split('@@');
			$('#descriptions').html(info[0]);
			eval(info[1]);
		});
	return false;
}
function get_map(store_id)
{

	$.get("/ax_get_map.php", {store_id: store_id},
		function(mapa)
		{
			var info = mapa.split('@@');
			$('#descriptions').html(info[0]);
			eval(info[1]);
		});
	
}
function get_guide_topics(id,sec_name)
{
		$.get("/ax_get_guide_topics.php", {id:id},
		function(topics)
		{
			$('#guide_topics').html(topics);
			$('#guide_title').html(sec_name);
			$('.menu_subitem_sel').addClass('menu_subitem');
			$('.menu_subitem').removeClass('menu_subitem_sel');
			$('#section_' + id).removeClass('menu_subitem');
			$('#section_' + id).addClass('menu_subitem_sel');
			$('#accordion').accordion({autoheight:false, navigation:true, header: 'a.topic_title',alwaysOpen: false});
		});
	
}

