var mainSection;//this is set in each document

function popitup(url) {
	newwindow=window.open(url,'name','height=590,width=615');
	if (window.focus) {newwindow.focus()}
	return false;
}

function scrollToAnchor(product) {
	//scrolls to the product directly, ### is the speed
	$.scrollTo('#'+product+'ScrollTo', 600);
	return false;
	
}

attachRollOverEvent = function(imageId){
	$(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").replace(/_0/, '_1')) } );	
	$(imageId).mouseout( function(){ if(!$(this).hasClass('noroll')) $(this).attr("src", $(this).attr("src").replace(/_1/, '_0')) } );
}

highlightMainNav= function(imageId){
	$(imageId).addClass("noroll");	
	$(imageId).attr("src", $(imageId).attr("src").split('_0').join('_2'));	
	
}
$().ready(function(){
	// Disable context menu on an element
	$("#headerLogo").noContext();

	// Search Input Disappear 
	$(".searchBox").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("searchBoxActive");
            $(this).val("");
        }
    });
    
    $(".searchBox").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).addClass("searchBoxActive");
            $(this).val($(this)[0].title);
        }
    });
    
	$(".searchBox").blur();
	
	//main section display
	if(mainSection){				   
		highlightMainNav(mainSection);
	}
	
	if(typeof subSection != 'undefined'){
		var img = $(subSection)[0].getElementsByTagName('IMG')[0];
		img.src = img.src.replace(/_0/, '_1');
		$(img).addClass('noroll');
	}
	
	$('#subNavMain div').each(function() { 
		if(typeof mainSection == 'undefined' || this.className != $(mainSection)[0].parentNode.className) {
			$(this).hide();
		}
	});
	
	if(typeof mainSection != 'undefined' && $(mainSection)[0].parentNode.className)
		$('#subNavMain').show();
	
	//rollover calls
	attachRollOverEvent("#subNavMain a img.roll");
	attachRollOverEvent("#rightContent a img.roll");
	attachRollOverEvent("#homeRightWrapper a img.roll");
	attachRollOverEvent("#mainContent #shortCutNav a img.roll");
	
	//show/hide content areas within a page
	$(".showHideWrapper .showHideHeader").click(function() {
		$(this).next().next().toggle("fast");
	})
	.next().next("div.showHideContent").hide();
	
		//show/hide content areas within a page (trigger link is last item)
	$(".showHideWrapper2 .header1B .headerLink").click(function() {
		$(this).parent().parent().next().toggle("fast");
		var moreState = $(this).parent().parent().next().next().find(".moreImg").attr("src");
		if(moreState){
			if(moreState == "images/common/btn_more.gif"){$(this).parent().parent().next().next().find(".moreImg").attr("src", $(this).parent().parent().next().next().find(".moreImg").attr("src").split('_more').join('_less'));}
			else{$(this).parent().parent().next().next().find(".moreImg").attr("src", $(this).parent().parent().next().next().find(".moreImg").attr("src").split('_less').join('_more'));}
		}
	})
	
	
	//show/hide content areas within a page (trigger link is last item)
	$(".showHideWrapper2 .showHideHeader2").click(function() {
		$(this).prev().toggle("fast");
		var moreState = $(this).find(".moreImg").attr("src");
		if(moreState){
			if(moreState == "images/common/btn_more.gif"){$(this).find(".moreImg").attr("src", $(this).find(".moreImg").attr("src").split('_more').join('_less'));}
			else{$(this).find(".moreImg").attr("src", $(this).find(".moreImg").attr("src").split('_less').join('_more'));}
		}
	})
	.prev("div.showHideContent2").hide();
	
	//this jumps to the appropriate product and displays the content
	var url = window.location.href;
	var prodQuery = url.split("#product-");
	if(prodQuery){var prodName = prodQuery[1];}	
	if(prodName){		
		//scrolls to the product directly, ### is the speed
		$.scrollTo('#'+prodName+'ScrollTo', 600);

	}
	
}

	

);

//IE function to force min-width style
function P7_limit(a,b){ //v1.1.3 by PVII-www.projectseven.com
 document.p7limit=a;document.p7min=b;
 if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
 if(window.attachEvent){window.attachEvent("onresize",P7_setMinWidth);
 window.attachEvent("onload",P7_setMinWidth);}else{onload=P7_setMinWidth;
 onresize=P7_setMinWidth;}}}P7_limit('siteWrapper',990);
function P7_setMinWidth(){ //v1.1.3 by PVII-www.projectseven.com
 var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
 var g=document.getElementById(theDiv);w=parseInt(document.p7min);
 if(g&&document.body&&document.body.clientWidth){gs=g.currentStyle;
 cw=parseInt(document.body.clientWidth);pl=parseInt(gs.paddingLeft);
 pr=parseInt(gs.paddingRight);ml=parseInt(gs.marginLeft);mr=parseInt(gs.marginRight);
 bl=parseInt(gs.borderLeftWidth);br=parseInt(gs.borderRightWidth);ml=ml?ml:0;
 mr=mr?mr:0;pl=pl?pl:0;pr=pr?pr:0;bl=bl?bl:0;br=br?br:0;ad=pl+pr+ml+mr+bl+br;
 if(cw<=w){w-=ad;g.style.width=w+"px";}else{g.style.width="auto";}}
}


//enables right click detection to disable contetxt menu

// jQuery Right Mouse Plugin
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// Visit http://abeautifulsite.net/notebook.php?article=68 for more information
// History: 1.00 - released (13 May 2008)
// TERMS OF USE
// This software is licensed under a Creative Commons License and is copyrighted (C)2008 by Cory S.N. LaViska.
// For details, visit http://creativecommons.org/licenses/by/3.0/us/
if(jQuery) (function(){
	
	$.extend($.fn, {
		
		rightClick: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					var evt = e;
					$(this).mouseup( function() {
						$(this).unbind('mouseup');
						if( evt.button == 2 ) {
							handler( $(this) );
							return false;
						} else {
							return true;
						}
					});
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		rightMouseDown: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					if( e.button == 2 ) {
						handler( $(this) );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		rightMouseUp: function(handler) {
			$(this).each( function() {
				$(this).mouseup( function(e) {
					if( e.button == 2 ) {
						handler( $(this) );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		noContext: function() {
			$(this).each( function() {
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		}
		
	});
	
})(jQuery);	
