$(document).ready(function(){
						   
	$('.nav-bar').tinyscrollbar();	
	$('.tabs').tabs(".panes > ul");
	$('.tabs2').tabs(".panes_a > div");
	$('.tabs3').tabs(".panes_b > div");
	$('.tabs4').tabs(".panes_c > div");
	$('.tabs5').tabs(".panes_d > div");
	$('.tabs6').tabs(".panes_e > ul");
	
	$('a.nav-scroll').bind('click',function(event){
		var $anchor = $(this);
		
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top-56
		}, 1500,'easeInOutExpo');
		/*
		if you don't want to use the easing effects:
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top
		}, 1000);
		*/
		event.preventDefault();
	});
	
	$('p#box1,a#box1,img#box1').hover(function(){
		$("img#box1").attr("src", "img/fetur2.jpg");
	}, function() {
		$("img#box1").attr("src", "img/fetur.jpg");
	});
	
	$('p#box2,a#box2,img#box2').hover(function(){
		$("img#box2").attr("src", "img/for-tur2.jpg");
	}, function() {
		$("img#box2").attr("src", "img/for-tur.jpg");
	});
	
	$('p#box3,a#box3,img#box3').hover(function(){
		$("img#box3").attr("src", "img/mostra-tur2.jpg");
	}, function() {
		$("img#box3").attr("src", "img/mostra-tur.jpg");
	});
	
	$('p#box4,a#box4,img#box4').hover(function(){
		$("img#box4").attr("src", "img/rod-tur2.jpg");
	}, function() {
		$("img#box4").attr("src", "img/rod-tur.jpg");
	});
	
    $.fn.parallax = function(options){
        var $$ = $(this);
        offset = $$.offset();
        var defaults = {
            "start": 0,
            "stop": offset.top + $$.height(),
            "coeff": 0.95,
            "initPos": $$.position().top,
            "type": "element"
        };
        var opts = $.extend(defaults, options);
        if(opts.type == "image"){
			if (navigator.appName=='Microsoft Internet Explorer'){
				opts.initPos =  parseInt($$.css('backgroundPositionY'));
			}
			else{
				opts.initPos = $$.css('background-position').split(' ');
        		opts.initPos = parseInt(opts.initPos[1]);
			}
        }
        return this.each(function(){
            $(window).bind('scroll', function() {
                var win = $(window),
                	windowTop = win.scrollTop();

                if((windowTop >= opts.start) && (windowTop <= opts.stop)) {
                	var prnt = $$.parent(),
                		parenttop = prnt.offset().top,
                		parentheight = prnt.height(),
                		winheight = win.height(),
                		parentloc;
                		
                	if (parenttop < 10) { parentloc = parenttop + winheight; } else { parentloc = parenttop; }
                	
                	if(opts.type == 'element'){
	                    newCoord = parseInt(opts.initPos) + ((parseInt(winheight) + parseInt(windowTop) - parseInt(parentloc)) * opts.coeff);
	                    //console.debug('initpos' + opts.initPos + ' newCoord: ' + newCoord + ' windowTop: ' + windowTop + ' parentoffsetTop: ' + $$.parent().offset().top + ' coeff:' + opts.coeff + ' winheight:' + $(window).height());
	                    $$.css({
	                        "top": newCoord + 'px'
	                	});
	                }
	                else if(opts.type == "image"){
	                	if (navigator.appName=='Microsoft Internet Explorer'){
	                		var newCoordY = $$.css('backgroundPositionY');
	                		newCoordY = opts.initPos + ((windowTop - parenttop) * opts.coeff);
	                		$$.css({
		                        "backgroundPositionY": newCoordY + 'px' 
		                	});
	                	}
	                	else{
	                		newCoord = $$.css('background-position').split(' ');
	                		newCoord[1] = opts.initPos + ((windowTop - parenttop) * opts.coeff);
	                		$$.css({
		                        "background-position": newCoord[0] + newCoord[1] + 'px' 
		                	});
	                	}
	                }
            	}
        	});
        });
    };
	
	//Nav Tracking	
	var $sections = $('#wrapper > .section'),
		navlocations = new Array($sections.length);
		
	$sections.each(function(i)
	{
		var $this = $(this),
			winH = parseInt($(window).height() / 3);
		navlocations[i] = { "start":parseInt($this.offset().top) - winH, "stop":parseInt($this.offset().top) + parseInt($this.height()), "id":$this.attr('id'),"isactive":false };		
	});
			
	$(window).scroll(function(){
		for(var i in navlocations) 
		{
			var scrolltop = $(window).scrollTop();
			
			if (scrolltop >= navlocations[i].start && scrolltop <= navlocations[i].stop) 
			{
				$('#inner-nav ul li a.active').removeClass('active');
				$('#inner-nav #'+navlocations[i].id+'-nav').addClass('active');
			}
			else if (scrolltop >= navlocations[i].stop)
			{
				$('#nav-inner ul li a.active').removeClass('active');				
			}
		}
	});
	
	// call dream plugin
	$('.para-element').each(function(){
	
		$(this).parallax({ 
			'coeff': $(this).attr('data-offset'),
			'stop': $(this).parents('.section').offset().top + $(this).parents('.section').height(),
			'start': $(this).parents('.section').offset().top - $(window).height()
		});
	
	});
	

	$('.para-image').each(function(){
	
		$(this).parallax({ 
			'coeff': $(this).attr('data-offset'),
			'stop': $(this).parents('.section').offset().top + $(this).parents('.section').height(),
			'start': $(this).parents('.section').offset().top - $(window).height(),
			'type' : 'image'
		});
	
	});

});
