/* 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
	$('.searchButton, .advSearchlink, .homeColB .links a, .fp-stage a .viewDetails, .searchBtn, .toggleAdvSearch, .textResize li a, .prev, .next, .downloadPDF, .largeimg, .backList, .printPage, .backListNews, .printPageNews, .savePage, .download, .downloads img, .view, .transparentHover, #r-products a .viewDetails, #s-products a .viewDetails').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();
		}
	}
});