 /* WPstudios/FedericaCau/CodingKoala : GenericSkeleton */

var homeImages = new Array();
var currImg = 1;
var cambioImg = 0;
var imagesReady = 0;
var timerPun; 
  
function faderPreloader(x)
{
  homeImages = x;
  for(i = 0; i < x.length; i++)
    $('<img />').attr('src', x[i]).load(function(){ imagesReady++; });      
  setTimeout("doHomeFader()", 2000);
}

function doHomeFader()
{
  if(imagesReady == homeImages.length)
  {
	if(cambioImg%2==0){
		$('#homeslider').animate({'opacity': 0.0}, 1800);
		$('#homeslider2').attr('src',homeImages[currImg++]);
		$('#homeslider2').animate({'opacity': 1.0}, 1800);
	}
	else{
		$('#homeslider2').animate({'opacity': 0.0}, 1800);
		$('#homeslider').attr('src',homeImages[currImg++]);
		$('#homeslider').animate({'opacity': 1.0}, 1800);
	}
	cambioImg++;
    if(currImg == homeImages.length) currImg = 0;
    timerPun = setTimeout("doHomeFader()", 7000);
  }
  else
  timerPun = setTimeout("doHomeFader()", 1000);    
}



// ----------------------------------------------------------
// CodingKoala : CUSTOM GENERIC PAGED SLIDER
// ----------------------------------------------------------
var gen_tPun;
var gen_curr_img   = 1;
var gen_prev_img   = 1;
var gen_max_img    = 1;
var gen_show_delay = 8 * 1000; // slider secs.
var gen_page_img   = 1;
var gen_page_width = 1;
var gen_slide_el; 
var dot_on  = '';
var dot_off = '';

function doSetSlideNum(el, n_imgs,p_imgs,w_imgs,d_on,d_off)
{
  dot_on  = d_on;
  dot_off = d_off;
  $('#dots').empty();
  
  gen_max_img     = n_imgs/p_imgs;
  gen_page_img    = p_imgs;
  gen_page_width  = p_imgs * w_imgs;
  gen_slide_el    = el;
  
  $(gen_slide_el).css('width', ((gen_max_img) * gen_page_width)+'px');

  for(i = 0; i < n_imgs; i++)
    $('#dots').append("<img id='dot_"+(i+1)+"' src='"+dot_off+"' alt='o' border='0' style='cursor: pointer; padding-left: 5px;' onclick='javascript:doShowN("+(i+1)+")' />");

  doShow();
}

function doShow()
{ 
  $(gen_slide_el).animate({left: (gen_curr_img - 1)*(-1*gen_page_width)+'px'},600);

  k = (gen_prev_img - 1) * gen_page_img;
  for(y = 0; y < gen_page_img; y++)
    $('#dot_'+(k+y+1)).attr('src', dot_off);

  k = (gen_curr_img - 1) * gen_page_img;
  for(y = 0; y < gen_page_img; y++)
    $('#dot_'+(k+y+1)).attr('src', dot_on);
   
  gen_prev_img = gen_curr_img;
  gen_curr_img++;
  if(gen_curr_img > gen_max_img) gen_curr_img = 1;

  gen_tPun = setTimeout("doShow()",gen_show_delay);
}


function doShowN(x)
{
  clearInterval(gen_tPun);
  gen_curr_img = x;
  doShow();
}

function doShowNext() 
{
  clearInterval(gen_tPun);
  doShow();
}


function doShowPrev() 
{
  clearInterval(gen_tPun);
  gen_curr_img = gen_prev_img - 1;
  if(gen_curr_img < 1) gen_curr_img = gen_max_img;
  doShow();  
}
// ----------------------------------------------------------
// END
// ----------------------------------------------------------


$(document).ready(function(){ 
	Cufon.now();
	// fix IE6 png issue
    $(document).pngFix();
    // init
    $("form.jqtransform").jqTransform();
    $(".form_contattaci").jqTransform();
    $('.defaultInputValue').defaultInputValue(); 
    //doSetSlideNum('#slider',7,1,960,'images/dot_on.gif','images/dot_off.gif');
    $('a[rel=gallery]').fancybox();
    $('a[rel=gallery_base]').fancybox();
    $('#current_language').click(function() { $('#choice').toggle(); });
});

function caricaListaAuto(_marca) {

    var url = 'servizi/ws_getcarlist.php';
    var dati = "filtro_marca="+_marca;

    $.ajax({
        type: "POST",
        url: url,
        data: dati,
        success: function(output){
            //alert(output);
            $("form.jqtransform").removeClass('jqtransformdone');
            $("#filtro_modello").html(output);
        },
        complete: function(){
          $("form.jqtransform").jqTransform();
        }
    });

}
