$(document).ready(function() {
	$('body').removeClass('static').addClass('dynamic');
	
	$('.language-selection .menu-language a').hover(
		function(e) {
			$('a.dot.'+$(this).attr('class')).addClass('active');
		},
		function(e) {
			$('a.dot.'+$(this).attr('class')).removeClass('active');
		}
	);

	if(typeof document.body.style.maxHeight !== "undefined") {
		$('.header').append('<div class="menu-extended" style="display:none;"></div>');
	}
	
	$('.header .menu-main a').mouseenter(
		function(e) {
			var a = $(this);
			var ul = a.next('ul');
			var li = $('.header .menu-main li');
			
			li.removeClass('out');

			if(ul.length === 0)
				return;

			$('.header .menu-extended').attr('rel',li.index(a.parent().get(0))).html(ul.clone()).css({ top:(a.offset().top+36)+'px', left:(a.offset().left-1)+'px' }).show();
		}
	).mouseleave(
		function(e) {
			$('.header .menu-extended').hide();
		}
	);
	
	$('.header .menu-extended').mouseenter(
		function(e) {
			$('.header .menu-main li').eq($('.header .menu-extended').attr('rel')).addClass('out');
			$('.header .menu-extended').show();
		}
	).mouseleave(
		function(e) {
			$('.header .menu-main li').removeClass('out');
			$('.header .menu-extended').hide();
		}
	);	
	
	$('.search input.text').focus(function() {
		if($(this).data('default') === undefined) {
			$(this).data('default', $(this).val());
		}
		if($(this).val() == $(this).data('default')) {
			$(this).val('');
		}
	}).blur(function() {
		if($(this).val() == '') {
			$(this).val($(this).data('default'));
		}
	});
	
	
	if($('.header .slider .screens img').length > 0) {	
		if($('.header .slider .screens img').length > 1) {
			$('.header .slider .screens').nivoSlider(
				{
					effect:'fade',
					slices:1,
					animSpeed:500,
					pauseTime:5000,
					directionNav:false,
					directionNavHide:true,
					controlNav:true,
					pauseOnHover:true,
					manualAdvance:false,
					beforeChange: function() {
						$('.header .slider .content div').each(function (i) {
							if($('.header .slider .screens').data('nivo:vars').currentSlide === i) {
								$(this).fadeOut();
							} else {
								$(this).css('display','none');
							}
						});
					},
					afterChange: function() {
						$('.header .slider .content div').each(function (i) {
							if($('.header .slider .screens').data('nivo:vars').currentSlide === i) {
								$(this).fadeIn();
							} else {
								$(this).css('display','none');
							}
						});
					}
				}
			);		
		}
		$('.header .slider .content div').each(function() {
			var s = $('.header .slider').eq(0);
			var e = $(this);
				e.css({
					display: 'none',
					position:'absolute',
					top: s.offset().top + s.height() - (e.height()+100),
					zIndex: 99
				});
		});
		$('.header .slider .content div').eq(0).fadeIn();
	}
	
	
	
	$('.tabs .menu-tabs a').click(function(e) {
		$('.tabs .tab').addClass('hidden');
		$('.tabs .menu-tabs a').removeClass('active');
		
		var a = $(this);
			a.addClass('active').blur();
		
		var hash = "#"+a.attr('href').split('#')[1];
		
			document.location.hash = hash;
		$(hash).removeClass('hidden');	
		e.preventDefault();	
	});
	
	
	/*$('.tabs').each(function(i,e) {		
		var hash = document.location.hash;		
		$('.tabs .menu-tabs a').each(function(i,e) {
			var a = $(e);
			if(a.attr('href') === hash) {
				a.trigger('click');
			}
		});		
	});*/
	
	$('.product-action a.compare').click(function(e) {
		//e.preventDefault();
	});
	
	$('form button.blue-button').add('form input.action').each(function(i,e) {
		var button = $(e);

		var text = button.attr('value') || button.text();		
			button.replaceWith('<a href="#" class="blue-button"><span>'+text+'</span></a>');
			
		 $('form a.blue-button').click(function(e) {
			$(this).closest('form').submit();			
			e.preventDefault();
		});
			
	});
	
	$('.product-gallery a').click(function(e) {
		$('.product-image img').attr('src',$(this).attr('href'));
		e.preventDefault();
	});
	
	if($('.news-gallery a').add('.product-actions a.video').length > 0) {
		$('.news-gallery a').add('.product-actions a.video').each(function(i,e) {
			
			var href = 	$(e).attr('href');
			var known = ['jpg','jpeg','png','gif'];
			
			if(href === "") 
				return;
			
			for(var i in known) {
				if(href.substr(-(known[i].length)) === known[i]) {
					return;
				}
			}
			
			var uid = "uid-"+Math.round(Math.random()*100000);
			var data = jQuery.parseJSON($(e).attr('rev'));
			
			$('body').append('<div style="display:none;"><div id="'+uid+'"></div></div>');
			
			if(href.substr(-3) === "swf") {
			
				swfobject.embedSWF(href, uid, data.width, data.height, "10.0.0", "/themes/fsp/swf/install.swf", {}, {quality:'high', allowscriptaccess:'sameDomain', wmode:'opaque'}, {id:uid, name:uid, align:'middle'});
				
			} else {				
				try {
					$('#'+uid).html('<object id="'+uid+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="'+uid+'" width="'+data.width+'" height="'+data.height+'"><param name="movie" value="/themes/fsp/swf/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file='+escape('../../'+href)+'" /><embed type="application/x-shockwave-flash" id="'+uid+'2" name="'+uid+'2" src="/themes/fsp/swf/player.swf" width="'+data.width+'" height="'+data.height+'" allowscriptaccess="always" allowfullscreen="true" flashvars="file='+escape(href)+'&autostart=true" /></object>');
				} catch(e) {}
				
				//swfobject.embedSWF("/themes/fsp/swf/player.swf", uid, data.width, data.height, "10.0.0", "/themes/fsp/swf/install.swf", {video:escape('../../'+href),autostart:true}, {quality:'high', allowscriptaccess:'always', allowfullscreen:'true', }, {id:uid, name:uid, align:'middle'});
				
			}
			$(e).attr('href','#'+uid);
			
		}).fancybox();	
	}
	
	$('.product-actions a.print').click(function(e) {
		window.print();
		e.preventDefault();
	}).show();
	
});
