// Jquery custom plugins


$.fn.opacity = function(_value) { 
    return $(this).css('opacity',_value);
};






// JavaScript Document

var curMapFocus = 0;
var curWfocus = 1;
var numdot = 1;
var widthW = 280 + 8;
var curMfocus = 1;
var numdot2 = 1;
var widthM = 280 + 8;
var ua = navigator.userAgent;
var checker = {
	iphone: ua.match(/(iPhone|iPod)/),
	ipad: ua.match(/(iPad)/),
	//blackberry: ua.match(/BlackBerry/),
	android: ua.match(/Android/)
};
var target;
var img;
var alink;
var txt;
var tA;
var tIEhack;
var cont;

try { document.execCommand('BackgroundImageCache', false, true); } catch (e) {} // [IE6] save flicker

if (typeof SORRIDENTE == 'undefined') var SORRIDENTE = {};

SORRIDENTE.V1 = {

	setup: function() {
		
		if ($('#home').is('*')) {			this.swapNavigation('.navi1');	 	}
		if ($('#course').is('*')) {			this.swapNavigation('.navi3');		}
		if ($('#jma').is('*')) {			this.swapNavigation('.navi4');		}
		if ($('#shop').is('*')) {			this.swapNavigation('.navi6');		}
		if ($('#contact').is('*')) {		this.swapNavigation('.navi7');		}
		
		
		JsRoller.initialize( 'rollover' );
		
		
		if ($('#openingslide').is('*')) {
			$("#openingslide").cycle({
				fx: 'fade',
				easing: 'easeOutExpo',
				speed: 3000,
				timeout: 6000,
				delay: 0
			});
		}
		
		$('a').each(function() {
			var id = (/^[^#]+(#.+)$/.exec(this.href) || [])[1];
			if (!id) return;
			$(this).click(function() {
				var top = (id == '#top') ? 0 : $(id).position().top - 0;				
				SORRIDENTE.V1.scroll_to(top,id);
				return false;
			});
		});	
		
		$('.roll').hover(function(){
			mapRollOn($(this).attr('rel'));
		}, function(){
			mapRollOut($(this).attr('rel'));
		});
		
		SORRIDENTE.V1.setup_sidenavi();
		
			
	},
	swapNavigation : function(_target){
		target = $(_target);
		alink = target.find('a');
		cont = alink.html();
		target.html(cont);
		img = target.find('img');
		txt = img.attr('src');
		tIEhack =  txt.split('images');
		tA = tIEhack[1].split('.');
		//alert(tA);
		img.attr('src', "images"+tA[0]+"_on."+tA[1]);
		//img.attr('src', 'images/btn_top_on.png');
		img.removeClass('rollover');	
	},
	
	scroll_to: function(top,id) {
		$('html, body').stop(true, false).animate(
			{ 	scrollTop: top },1100, 'easeInOutExpo',function(){ document.location.hash = id } 
		);
	},
	scroll_to_id: function(id) {
			var top = (id == '#top') ? 0 : $(id).position().top - 0;				
			$('html, body').stop(true, false).animate({ 	scrollTop: top },1100, 'easeInOutExpo' );		
	},
	scroll_to_id_hash: function(id) {
			var top = (id == '#top') ? 0 : $(id).position().top - 0;				
			$('html, body').stop(true, false).animate({ 	scrollTop: top },1100, 'easeInOutExpo', function(){ window.location.hash = id } );
	},
	setup_sidenavi: function(){	
		$('.btn_newsletter').mouseover(function(){	$(this).stop(true, false).animate({ left:0 }, {duration: 500, easing: "easeOutExpo"});});
		$('.btn_newsletter').mouseout(function(){	$(this).stop(true, false).animate({ left:95 }, {duration: 500, easing: "easeOutExpo"});});
		$('.btn_twitter').mouseover(function(){		$(this).stop(true, false).animate({ left:0 }, {duration: 500, easing: "easeOutExpo"});});
		$('.btn_twitter').mouseout(function(){		$(this).stop(true, false).animate({ left:95 }, {duration: 500, easing: "easeOutExpo"});});
		
		$(window).scroll(function(){
			if(checker.iphone || checker.ipad){
				$('#fixbtns').css({
					"position" : "absolute",
					"top" : $(window).scrollTop() + 80,
					"right" : 0
				});
				//alert($(window).scrollTop());
			}
			
		});	
	}
		
};



$(document).ready(function() {
	SORRIDENTE.V1.setup();		
});


