$(document).ready(function() {
	
	// Gestione target blank links con doctype strict
	// This is how it works:
	// <a href="http://www.tripwiremagazine.com/" rel="external">tripwiremagazine.com</a>
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});

	// gestione IMG HOVER
	$(".mHover").each(function() {
		var src = $(this).attr('src');
		var extension = src.substring(src.lastIndexOf('.'), src.length);
		$(this).mouseover(function() {
			$(this).attr('src', src.replace(extension,'-on' + extension));
		}).mouseout(function() {
			$(this).attr('src', src);
		});
	});
	
	obj.round();
	obj.hover();
	$('h1').hide();
	
	obj.privacy();
	obj.menuHmtl();
	
	var height = $(window).height();
	$('#flashContainer').css('height', height+'px');
	
	$('.menu').show();
});

$(window).resize(function() {
	obj.resizeSwf();
});

var obj = {
	
	resizeSwf : function () {
		var height = $(window).height();
		$('#flash').attr('height', height);
		
	},
	
	changeDeep : function (status) {
		if (status == 'over') {
			$('#menuFlash').css('z-index', 10);
			$('#textarea').css('z-index', 9);
		}
		if (status == 'out') {
			$('#menuFlash').css('z-index', 9);
			$('#textarea').css('z-index', 10);
		}
	},
	
	page : function (domain) {
		var url        = window.location.href;
		var part       = url.substr(domain.length);
		
		if (part != '/' && part != '/index-it.php' && part != '/index-en.php'&& part != '/index-fr.php' ) {
			if (url.indexOf("#") == -1) {
				window.location.href = domain+'#'+part;
			}
		}
	},
	
	initCurvy : function () {
		var settings = {
		    tl: { radius: 7 }
	      , tr: { radius: 7 }
	      , bl: { radius: 7 }
	      , br: { radius: 7 }
	      , antiAlias: true
	    };
		return settings;
	},
	
	round : function () {
		if ($('.round').length > 0) {
			curvyCorners(obj.initCurvy(), ".round");
			$('.border').hide();
			//$('.video').hide();
			
			$('.round').click(function () {
				
				if ($(this).hasClass('youtube')) {
					
					if ($("a[rel=vvv_1]").attr("href") != undefined) {
						$("a[rel=vvv_1]").fancybox({
							'padding'		: 0,
							'autoScale'		: false,
							'transitionIn'	: 'none',
							'transitionOut'	: 'none',
							'title'			: this.title,
							'width'		    : 680,
							'height'		: 390,
							'href'			: $('a[rel=vvv_1]').attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
							'type'			: 'swf',
							'swf'			: {
							   	'wmode'		        : 'transparent',
								'allowfullscreen'	: 'true'
							}
						});
					}
					
					if ($("a[rel=vvv_2]").attr("href") != undefined) {
						$("a[rel=vvv_2]").fancybox({
							'padding'		: 0,
							'autoScale'		: false,
							'transitionIn'	: 'none',
							'transitionOut'	: 'none',
							'title'			: this.title,
							'width'		    : 680,
							'height'		: 390,
							'href'			: $('a[rel=vvv_2]').attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
							'type'			: 'swf',
							'swf'			: {
							   	'wmode'		        : 'transparent',
								'allowfullscreen'	: 'true'
							}
						});
					}
					
					if ($("a[rel=vvv_3]").attr("href") != undefined) {
						$("a[rel=vvv_3]").fancybox({
							'padding'		: 0,
							'autoScale'		: false,
							'transitionIn'	: 'none',
							'transitionOut'	: 'none',
							'title'			: this.title,
							'width'		    : 680,
							'height'		: 390,
							'href'			: $('a[rel=vvv_3]').attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
							'type'			: 'swf',
							'swf'			: {
							   	'wmode'		        : 'transparent',
								'allowfullscreen'	: 'true'
							}
						});
					}
					
					if ($("a[rel=vvv_4]").attr("href") != undefined) {
						$("a[rel=vvv_4]").fancybox({
							'padding'		: 0,
							'autoScale'		: false,
							'transitionIn'	: 'none',
							'transitionOut'	: 'none',
							'title'			: this.title,
							'width'		    : 680,
							'height'		: 390,
							'href'			: $('a[rel=vvv_4]').attr('href').replace(new RegExp("watch\\?v=", "i"), 'v/'),
							'type'			: 'swf',
							'swf'			: {
							   	'wmode'		        : 'transparent',
								'allowfullscreen'	: 'true'
							}
						});
					}
					
				} else {
					$("a[rel=group]").fancybox({
						'transitionIn'		: 'none',
						'transitionOut'		: 'none',
						'titlePosition' 	: 'over'
					});
				}
				
			});
		}
		
		if ($('#contatti').length > 0) {
			//uso dd roundies perchè curvy cornes non applica bene 
			//il round al png di sfondo e al punlsante invio nel form contatti
			//DD_roundies.addRule('#contatti', '7px', true);
			if ($.browser.msie) {
				curvyCorners(obj.initCurvy(), "#contatti");
			}
			DD_roundies.addRule('#submit', '7px', true);
		}
		
		if ($('#text').length > 0) {
			DD_roundies.addRule('.scrollCont', '7px', true);
		}
		
	},
	
	hover : function () {
		$('.imgContainer').mouseover(function () {
			if ($(this).hasClass('youtube')) {
				//$(this).find('.video').show();
			} else {
				$(this).find('.border').show();
			}
		}).mouseout(function() {
			if ($(this).hasClass('youtube')) {
				//$(this).find('.video').hide();
			} else {
				$(this).find('.border').hide();
			}
		});
	},
	
	showText : function () {
		if ($('.scroll-pane').length > 0) {
			$('.scroll-pane').addClass('scroll-loading');
			$('#textarea').fadeIn(500, obj.scroll);
		} else {
			$('#textarea').fadeIn(500);
		}
	},
	
	openOverlay : function () {
		$.fancybox(			
			{
	        	  'autoDimensions'	: false
				, 'width'         	: 600
				, 'height'          : '100%'
				, 'transitionIn'	: 'none'
				, 'transitionOut'	: 'none'
				, 'href'            : '/private/'
			}
		);
	},
	
	privacy : function ()  {
		if ($('.privacy a').length > 0) {
			$('.privacy a').click(function () {
				$.fancybox({
					'titlePosition'		: 'inside',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'inline',
					'href'              : '#testo-privacy',
					'content'           : $('#testo-privacy').html()
				});
			});
		}
		
	},
	
	noteLegali : function () {
		$.fancybox(			
			{
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'inline',
				'type'				: 'inline',
				'href'              : '#testo-note-legali',
				'content'           : $('#testo-note-legali').html()
			}
		);
	},
	
	scroll : function () {
		if ($('.scroll-pane').length > 0) {
			$('.scroll-pane').removeClass('scroll-loading').jScrollPane({
				showArrows: true,
				horizontalGutter: 10
			});
			
		}
	},
	
	menuHmtl : function () {
		$('.menu a:first').addClass('first');
		$('.menu a:last').addClass('last');
	}
};

window.changeDeep = obj.changeDeep;
//window.noteLegali = obj.noteLegali;
