/******************
 *	HOVER THUMBS  
 ******************/

function hoverThumbs() {
if (!$.browser.msie || $.browser.version > 6.0) {


/*	SETS START POSITION OF ANIMATION */
	$('.product_thumbtext').css({
		'opacity':'0.0',
		'height':'10px'
	});


/*	MOUSE ENTER - THUMBNAIL IMAGE */
	$('[Class^=product_overview]').mouseenter(function() {
		$(this).find('.product_thumbtext').stop().animate({
			'opacity':'0.8',
			'height':'30px'
		},300);		
		var product = $(this).find('.product_thumbtext').html();
		$('#prodnav').find('ul li a:contains("'+product+'")').css('color','#A10101');
	});	
	

/*	MOUSE LEAVE - THUMBNAIL IMAGE */	
	$('[Class^=product_overview]').mouseleave(function() {
		$('.product_thumbtext').stop().animate({
			'opacity':'0',
			'height' : '10px'
		},300);
		
		var product = $(this).find('.product_thumbtext').html();
//		var product = product.toLowerCase();

		$('#prodnav').find('ul li a:contains("'+product+'")').css('color','');
	});
	

/*	MOUSE ENTER - MENU LINK */
	$('#prodnav ul li a').mouseenter( function() {
		var product = $(this).html();
//		var product = product.toUpperCase();
		$('[Class^=product_overview]').find('.product_thumbtext:contains("'+product+'")').stop().animate({
			'opacity':'0.8',
			'height':'40px'
		},300);		
	});


/*	MOUSE LEAVE - MENU LINK */
	$('#prodnav ul li a').mouseleave( function() {
		var product = $(this).html();
//		var product = product.toUpperCase();
		$('[Class^=product_overview]').find('.product_thumbtext:contains("'+product+'")').stop().animate({
			'opacity':'0',
			'height':'10px'
		},300);
	});
}}


/******************
 *	NEWS TOGGLE
 ******************/

function newsToggle() 
{
	$('#newsToggle').html('<img src="pub/images/icons/close.png" />');
	
	$('#newsToggle').toggle	(function(){
		$(".news_wrapper").animate({
			'opacity':'0'
		},800,function() {
			$('#newsToggle').animate({
			'left':'5px'
			},800,function(){$('#newsToggle').html('<img src="pub/images/icons/open.png" />');});
		}
		);
	}, function() {
		$(".news_wrapper").animate({
			'opacity':'0.8'
		},800,function() {
			$('#newsToggle').animate({
			'left':'200px'
			},800,function(){$('#newsToggle').html('<img src="pub/images/icons/close.png" />');});
		}
		);

	});
	
}

function contactForm()
{
$('#contactform input, #contactform textarea').focus(
	function()
	{
		$(this).prev().animate({'color':'#A10101'},600);	
	});

$('#contactform input, #contactform textarea').blur(
	function()
	{
		$(this).prev().animate({'color':'#595959'},600);	
	})
	

}


/****************************
 *	FIRST PAGE IMAGE ROTATOR 
 ****************************/

function imageRotator(){
	var speed = 1500;
	var pausespeed = 2000;
	var pause = false;
	var i = 0
	
	/*imgSrc = 'pub/images/icons/merinfo.png';
	$('#rotator').append('<a class="rotatorPauseImg" href=""><img src="'+imgSrc+'" /></a>');
	var pauseImage = $('.rotatorPauseImg')
	pauseImage.hide();*/
	
	$('#rotator li:first').siblings('li').hide();
	
	$(window).load(
		rotate($('#rotator li:visible:first'))
	);

	function rotate(element) {

		if(pause) {
			return;
		}
		
		var current_a = $('#rotator_controls a.current');
		
		var $next_li = 	$(element).next('li').length ?
						$(element).next('li') : 
						$('#rotator li:first');

		var $next_a = 	$('#rotator_controls a.current').parent('li').next('li').length ?
						$('#rotator_controls a.current').parent('li').next('li').find('a') :
						$('#rotator_controls a:first');

		current_a.removeClass('current');
		$next_a.addClass('current');

		function doIt() {
			if(pause != true)
				rotate($next_li);			
		}
	
		$(element).fadeOut(speed);

		$($next_li).fadeIn(speed, function() {
			setTimeout(doIt, pausespeed);
		});
	};
	
	/* Pause on Mouse Enter */	
	if($('#rotator a')[1])
	{
		$('#rotator').mouseenter(function(){			
			pauseImage.fadeIn(1500, function(){ 
				hoverlink = $('#rotator li:visible a').attr("href");
				console.log(hoverlink);
				pauseImage.attr("href",hoverlink);
			});
			pause = true;		
		});
	
		/* Play again on Mouse Leave */	
		$('#rotator').mouseleave(function(){
			pauseImage.fadeOut(800);
			pause = false;
			rotate('#rotator li:visible:first');
		});
	}		
};



function downloadPreview() {
	var previewImg = $('#prevImg');
	
	$('.downloadLink').hover(function(){
		var fileName = $(this).attr("href");
		var fileExt = fileName.substr(fileName.lastIndexOf('.')+1);
			
		if (fileExt == "pdf" || fileExt == "doc" || fileExt == "mp4")
		{
			console.log(fileExt);
			linkSrc = "pub/downloadthumb/icons/" + fileExt + ".png";
			previewImg.attr("src",linkSrc);
		}
		
		if ( fileExt == "jpg" || fileExt == "gif" || fileExt == "png" || fileExr == "jpeg" )
		{	
			var linkSrc = fileName;
			linkSrc = linkSrc.replace("/download/","/downloadthumb/");
			previewImg.attr("src",linkSrc);
		}
	}, function(){
		previewImg.attr("src","pub/downloadthumb/icons/preview.png");
	});
};




