// @info 	Rollover effects on menu and submenu
// @usage	$.navigation({options});
jQuery.navigation = function(options) {

	var defaults = {
			 firstBackground:	'#457a9d'
			,secondBackground: '#6a90a9'
	};
	var opt = jQuery.extend(defaults, options);


	jQuery('.nav-bar ul.sf-menu li')
		.hover(
			function(){
				jQuery(this).css({'background': opt.firstBackground});
				//jQuery(this).children('ul').show();
			},
			function(){
				jQuery(this).css({'background': ''});
				//jQuery(this).children('ul').hide();
			}
		);

	jQuery('.nav-bar ul.sf-menu li ul li')
		.hover(
			function(){
				jQuery(this).css({'background': opt.secondBackground});
			},
			function(){
				jQuery(this).css({'background':''});
			}
		);
	

};

// @info 	Disable the click for element selected
// @usage	$('html > element > a').disable();
jQuery.fn.disable = function() {
	return this.each(function(){
		jQuery(this).click(function(){ return false; });
	});
}

// @info 	Remove borders for li elements (only for ie)
// @usage	$.removeNavBorders();
jQuery.removeNavBorders = function() {
	if(jQuery.browser.msie){
		jQuery('#suckerfishnav li:first').css({'border-left':'0px'});
		jQuery('#suckerfishnav li:last').css({'border-right':'0px'});

		jQuery('#suckerfishnav li ul li:first').css({'border-top':'0px'});
		jQuery('#suckerfishnav li ul li:last').css({'border-bottom':'0px'});	
	}
}

// @info 	Check current pag
// @usage	if($.isPage('pageName'))
jQuery.isPage = function(checkFor) {

	var url = window.location.pathname;	
	var page = url.split('/');
	
	var thePage = ( page[1] == 'en' || page[1] == 'it' || page[1] == 'pl' )? page[2] : page[1];
	
	if(checkFor == thePage){
		return true;
	}else{
		return false;
	}
	
}

// @info 	If the console is active this function allow you to show a variable into it
// @usage	$.debug( variable_name );
jQuery.debug = function(message) {
	if(window.console){
		console.debug(message);
	}else{
		alert(message)
	}
}

jQuery.callTip = function(){
	
	var $ = jQuery;
	
	$('a.prod-icon')
		.each(
			function()
			{
				$(this).qtip(
				{
					content: $('#'+ $(this).attr('rel') ).html(), // Give it some content
					position: {
						corner: {
							target: 'topMiddle',
							tooltip: 'bottomMiddle'
						},
						adjust: { 
							y: 0,
							screen: true
						}
					},
					hide: {
						fixed: true,
						delay: 240
					},
					style: {
						width: 430,
						border: {
							color 	: '#bbbbbb',
							width 	: 1,
							radius 	: 3
						},
						tip: {
							corner: 'bottomMiddle',
							size: { x: 16, y: 10 }
						},
						cursor: 'pointer',
						padding: '10px',
						name: 'light'
					}
				});
			}
		);


	jQuery('.box-prodotti > a')
		.each(
			function()
			{
				jQuery(this).qtip(
						{
							content: '<a href="'+jQuery(this).attr('href')+'">'+jQuery(this).attr('rel')+'</a>', // Give it some content
							position: {
								corner: {
									target: 'topMiddle',
									tooltip: 'bottomMiddle'
								},
								adjust: { x: -10 }
							},
							hide: {
								fixed: true,
								delay: 240
							},
							style: {
								border: {
									color : '#0d6d9f',
									width : 1
								},
								tip: {
									corner: 'bottomMiddle',
									size: { x: 16, y: 10 }
								},
								cursor: 'pointer',
								padding: '6px 10px',
								name: 'light'
							}
						}
					)

			}
		)
/*
	jQuery('a.pdf')
		.each(function()
			{
				$this = jQuery(this);
				jQuery(this)
					.disable()
					.qtip(
					{
						content: {
							title: {
								text: 'Scarica la scheda tecnica',
								button: 'Chiudi'
							},
							text: '<div class="row"><span>Tipo di file</span> PDF</div>' +
									'<div class="row"><span>Peso del file</span> '+$this.attr('rel')+' KB</div>' +
									'<div class="row"><span>Link</span> <a href="'+ $this.attr('href') +'">clicca qui per avviare il download</a></div>'
						},
						position: {
							target: jQuery(document.body), // Position it via the document body...
							corner: 'center' // ...at the center of the viewport
					   },
						show: {
							when: 'click', // Show it on click
							solo: true // And hide all other tooltips
						},
						hide: false,
						style: {
							width: 450,
							padding: '14px',
							border: {
								width: 9,
								radius: 9,
								color: '#666666'
						   },
							name: 'light'
						},
						api: {
							beforeShow: function()
							{
								// Fade in the modal "blanket" using the defined show speed
								jQuery('#qtip-blanket').fadeIn(this.options.show.effect.length);
							},
							beforeHide: function()
							{
								// Fade out the modal "blanket" using the defined hide speed
								jQuery('#qtip-blanket').fadeOut(this.options.hide.effect.length);
							}
						}
					});
	
			}
		)
*/	
	jQuery('a.zoom')
		.each(function()
			{
				$this = jQuery(this);
				jQuery(this)
					.disable()
					.qtip(
					{
						content: {
							title: {
								text: $this.attr('title'),
								button: 'Chiudi'
							},
							text: '<img src="'+$this.attr('rel')+'" alt="" />'
						},
						position: {
							target: jQuery(document.body), // Position it via the document body...
							corner: 'center' // ...at the center of the viewport
					   },
						show: {
							when: 'click', // Show it on click
							solo: true // And hide all other tooltips
						},
						hide: false,
						style: {
							width: { max: 700 },
							padding: '14px',
							border: {
								width: 9,
								radius: 9,
								color: '#666666'
						   },
							name: 'light'
						},
						api: {
							beforeShow: function()
							{
								// Fade in the modal "blanket" using the defined show speed
								jQuery('#qtip-blanket').fadeIn(this.options.show.effect.length);
							},
							beforeHide: function()
							{
								// Fade out the modal "blanket" using the defined hide speed
								jQuery('#qtip-blanket').fadeOut(this.options.hide.effect.length);
							}
						}
					});
	
			}
		)
	
	jQuery('<div id="qtip-blanket">')
		.css({
			position: 'absolute',
			top: jQuery(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
			left: 0,
			height: jQuery(document).height(), // Span the full document height...
			width: '100%', // ...and full width

			opacity: 0.7, // Make it slightly transparent
			backgroundColor: 'black',
			zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
		})
		.appendTo(document.body) // Append to the document body
		.hide(); // Hide it initially

}
