function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/strpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

var typewriter = function() {
	
	eventi_el = $("#eventi");	
	eventi_HTML = eventi_el.html();	
	eventi_el.typewriter();	
	$("#eventi").html("");
};

jQuery(document).ready(function() {
    $("h1").animate({         
        paddingLeft: "0px"
      }, 4000, 'linear', typewriter);
    
    
    if(!strpos(document.location, 'tour', 0))
    {		
		carosello_width = $('#carosello').width();
		immagini_che_ci_stanno = carosello_width / 165 | 0;
		spazio_rimanente = carosello_width - immagini_che_ci_stanno * 160;
		margin_left = spazio_rimanente / (immagini_che_ci_stanno) | 0;
		resto = spazio_rimanente % (immagini_che_ci_stanno);
		img_width = 159 + margin_left;
		carosello_inner_html = '';
		
		for(i = 0; i < immagini_che_ci_stanno - 1; i++)
		{		
			carosello_inner_html = carosello_inner_html + '<a href="http://www.campingmarecchia.it/images/resize.php?file='+ immagini[i] +'&imgWidth=800&imgHeight=600"><img style="margin-right:1px" src="http://www.campingmarecchia.it/images/resize.php?imgWidth='+img_width+'&imgHeight=90&file='+ immagini[i] +'"></a>';
		}
		ultima_width = img_width + resto;
		
		j = i + 1;
		carosello_inner_html = carosello_inner_html + '<a href="http://www.campingmarecchia.it/images/resize.php?file='+ immagini[j] +'&imgWidth=800&imgHeight=600"><img src="http://www.campingmarecchia.it/images/resize.php?imgWidth='+ultima_width+'&imgHeight=90&file='+ immagini[j] +'"></a>';
		
		$('#carosello').html(carosello_inner_html);	
		$('#carosello a').lightBox();
	}
	
	$('#gallery a').lightBox();
	$("#eventi").width($('#footer').width() - 400);
	
	altezza_contenuto_1 = $("#contenuto-1").height();
	margin_tappo = 50;
	
	if(altezza_contenuto_1 < 300)
	{
		margin_tappo += 300 - altezza_contenuto_1;
	}
	
	altezza_buco = $("#contenuto-2").height() - altezza_contenuto_1;
	
	if(altezza_buco > 180)
	{
		larghezza_buco = $("#contenuto-1").width() * 2 - 10;
		altezza_buco = larghezza_buco / 16 * 4.5 | 0;
		
		$("#contenuto-1").append('<div style="width:'+larghezza_buco+'px;height:'+altezza_buco+'px;margin-top:'+margin_tappo+'px; background:url(http://www.campingmarecchia.it/images/resize.php?imgWidth='+larghezza_buco+'&imgHeight='+altezza_buco+'&crop=true&file='+ immagini[i++] +')"><a style="display:block; width:100%; height:100%" href="tour.php">&nbsp;</a></div>');		
		
	}
	$('#flash-post').cycle({timeout: 5000,speed: 2500});
});

