
function cerca(idioma, cami)
{
	var valorCerca=$("#search").val();
	var urlCerca=cami+idioma+'/search/'+valorCerca+'/';
	location.href=urlCerca;
}

function botoForm(){
    $('#form input.search').each(function(){
        $(this).data( "txt", $.trim($(this).val()) );
    }).focus(function(){
        // On focus test for default saved value and if not the same clear it
        if ( $.trim($(this).val()) === $(this).data("txt") ) {
            $(this).val("");
        }
    }).blur(function(){
        // Use blur event to reset default value in field that have class clear
        // but ignore if class once is present
        if ( $.trim($(this).val()) === "" && !$(this).hasClass("once") ) {
            //Restore saved data
            $(this).val( $(this).data("txt") );
        }
    });
}

/* Aquest script fa una transició  quan carrega les diferents pągines */
function transicio_original() {
	
	function redirectPage() {
		window.location = linkLocation;		
	}
	
	$("body").css("display", "none");
	
	
    $("body").fadeIn(500);
	
	$("a.transition").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("body").fadeOut(500, redirectPage);		
	});

	
		$("a.submenu").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("body").fadeOut(500, redirectPage);		
		//		redirectPage();
	});

		    
	$("a.selected").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("body").fadeOut(500, redirectPage);				
	});

	
}

function transicio() {
	
	function redirectPage() {
		window.location = linkLocation;		
	}
	
	
    $("#c_mosaic").fadeIn(500);
	
    
	$("a.transition").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("#c_mosaic").fadeOut(500, redirectPage);		
	});
	
	
		$("a.submenu").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("#c_mosaic").fadeOut(500, redirectPage);		
		//		redirectPage();
	});
	
		    
	$("a.selected").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("#c_mosaic").fadeOut(500, redirectPage);				
	});
	
		precargar();
	
}


function sliding(){
	//for each description div...
	$('div.description').each(function(){
		$(this).css('opacity', 0);//...set the opacity to 0...
		$(this).css('width', $(this).siblings('img').width());		//..set width same as the image...
		//...get the parent (the wrapper) and set it's width same as the image width... '
		$(this).parent().css('width', $(this).siblings('img').width());		
		$(this).css('display', 'block');		//...set the display to block
	});
	$('div.img_on').each(function(){
		$(this).css('opacity', 0);
		$(this).css('width', $(this).siblings('img').width());
		$(this).parent().css('width', $(this).siblings('img').width());
		$(this).css('display', 'block');
	});
	$('div.wrapper').hover(function(){
		//when mouse hover over the wrapper div
		//get it's children elements with class descriptio
		//and show it using fadeTo
//		$(this).children('.description').stop().fadeTo(500, 1);
//		$(this).children('.img_on').stop().fadeTo(500, 1);
		$(this).children('.description').stop().fadeTo('fast', 1);
		$(this).children('.img_on').stop().fadeTo('fast', 1);
		
	},function(){
		//when mouse out of the wrapper div
		//use fadeTo to hide the div
//		$(this).children('.description').stop().fadeTo(500, 0);
//		$(this).children('.img_on').stop().fadeTo(500, 0);
		$(this).children('.description').stop().fadeTo('fast', 0);
		$(this).children('.img_on').stop().fadeTo('fast', 0);

	});
	
}

function filtreMosaic() {
	$('.column li img').animate({'opacity' : 0.5}).hover(function() {
		$(this).animate({'opacity' : 1});
		}, function() {
			$(this).animate({'opacity' :  0.5});
	});
}


function bugIpod(){
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{
		/*$("#screen").css("position", "static");
		$("#nav").css("position", "static");
		$("#portfolio_2").css("position", "static");
		$("#copyright").css("position", "static");
		$("#screen").css("position", "static");
		$("#creative").css("position", "static");*/
		$("#screen").css("height", "1000000px");
		$("#screen").css("width", "1000000px");
		$("#transition").css("height", "1000000px");
		$("#transition").css("width", "1000000px");		
	};
}

function preCarga(imagenes) 
{
	//alert("dins");
	var i;
	var lista_imagenes = new Array();
	for(i in imagenes){
		lista_imagenes[i] = new Image();
		lista_imagenes[i].src = imagenes[i];
	}
} 

function precargar() {

	//$("#c_precarga").css("visibility", "visible");
	imgs = document.images;
	precargadas = true;
	for (var i = 0, total = imgs.length; i < total; i ++)
		precargadas = (precargadas && imgs[i].complete);
	//if (precargadas){ document.body.style.visibility = "visible";}

	if (precargadas){ 
		//$("#c_precarga").css("visibility", "hidden");
		//if (origen == 'mosaic') {$("#c_mosaic").css("visibility", "visible");alert('mosaic');}
		//else if (origen == 'projecte') {$("#proyecto_img").css("visibility", "visible");alert('projecte');}	
		//$("#c_mosaic").css("visibility", "visible");
		$("#c_mosaic").fadeIn(500);
//		$("#proyecto_img").fadeIn(500);
	}
	else setTimeout("precargar()", 100);
}

function inicialitzar(){

	transicio(); 
	sliding();
	botoForm();
	bugIpod();
	
//	filtreMosaic();

}


$(inicialitzar);
