/* molex jquery scripts */

$(document).ready( function(){
	
	// boring version
	$('#mainNav li').each(function(){
		$(this).hover(function(){
			//$('ul', this).fadeIn(200);
			$('ul', this).show();
		},
		function(){
			//$('ul', this).fadeOut(200);
			$('ul', this).hide();
		});
	});
	
	
	$('.featuredProducts li a').each(function(){
		$(this).click(function(){
			$('.fp-stage .featuredImg').attr({"src" : $('img', this).attr("src")});
			$('.fp-stage .productName').text( $('span', this).text() );
			$('.fp-stage a').attr({"href" : $(this).attr("href")});
			return false;
		});
	});
	
	$('.toggleAdvSearch').toggle(function(){
		$('.advSearch').slideDown(110);
		$('img', this).attr({src: '/images/links/adv-search-options-on.gif'});
	}, function(){
		$('.advSearch').slideUp(110);
		$('img', this).attr({src: '/images/links/adv-search-options.gif'});
	});
	
	// product detail tabs
	$('.productDetail').tabs({ fxFade: true, fxSpeed: 'fast' });
	$('.productDetail h4').hide();	
	$('.relatedProducts').tabs({ fxFade: true, fxSpeed: 'fast' });
	$('.relatedProducts h4').hide();	

	$('#productFilter').tabs({ fxFade: true, fxSpeed: 'fast' });

	// print?
	$('.printPage').click(function(){
		window.print();
		return false;
	});
	
	
	// for FontSizer
	var options = { min: -2, max: 2};
	//Initialize the font sizer for the site.
	$.FontSizer.Init(options);
	
	$('.sizeDown').click(function(){ return false; });
	$('.sizeUp').click(function(){ return false; });
	
	// transparency on these hovers
	var hoverItems = '.searchButton';
	hoverItems += ', .advSearchlink';
	hoverItems += ', .homeColB .links a';
	hoverItems += ', .fp-stage a .viewDetails';
	hoverItems += ', .searchBtn';
	hoverItems += ', .toggleAdvSearch';
	hoverItems += ', .textResize li a';
	hoverItems += ', .prev';
	hoverItems += ', .next'; 
	hoverItems += ', .downloadPDF';
	hoverItems += ', .largeimg';
	hoverItems += ', .backList';
	hoverItems += ', .printPage';
	hoverItems += ', .backListNews';
	hoverItems += ', .printPageNews';
	hoverItems += ', .savePage';
	hoverItems += ', .download';
	hoverItems += ', .downloads img';
	hoverItems += ', .view';
	hoverItems += ', .view img';
	hoverItems += ', .transparentHover';
	hoverItems += ', #r-products a .viewDetails';
	hoverItems += ', #s-products a .viewDetails'
		
		$(hoverItems).hover( function(){ 
			$(this).css({'opacity': 0.7}); 
		},	function(){ 
			$(this).css({'opacity': 1}); 
		});
		
	// get the url
	var url = new String(document.location);
	url = url.split('.html?');
	url = url[1];
	if(url){
		//if(url.match(/true/) || url.match(/AdvanceSearch/) || url.match(/RegionId/)){
		if(url.match(/advance/)){
			$('.advSearch').show();
			$('.toggleAdvSearch img').attr({src: '/images/links/adv-search-options-on.gif'});
		}
		if(url.match(/ProductSearch/)){
			$('#productFilter ul.tabs-nav li').each(function(){
				$(this).removeClass('tabs-selected');
			});
			// then add it to search product tab
			$('.sp-tab').parent('li').addClass('tabs-selected');
			$('#filterProducts').hide();
			$('#searchProducts').show();
		}
	}
});
