jQuery(function(){
	if(jQuery('#leftPromotion').length==0)	return false;
	
	var so = new SWFObject("/flash/categories_promo.swf?cPath=" + PM_Config.get('cPath'), "promo", "175", "275", "7", "#ffffff");
	so.addParam("allowScriptAccess", "sameDomain");
	so.addParam("wmode", "transparent");
	so.addParam("movie", "/flash/categories_promo.swf?cPath=" + PM_Config.get('cPath'));
	so.addParam("quality", "high");
	so.addParam("bgcolor", "#ffffff");
	so.write("leftPromotion");
});
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;

jQuery.noConflict();

jQuery(function(){
    // Round element corners
	jQuery(".sidebar-box").corner();
	jQuery(".rounded-top").corner("top");
	jQuery(".left-nav").corner("bottom");
	
	jQuery("#header #categories-navigation li.top-nav").hoverIntent( 
		function(){
			jQuery(this).addClass("hover");
			jQuery(this).find(".menu").show();
		}, 
		function(){
			jQuery(this).removeClass("hover");
			jQuery(".menu").hide();
		}
	);
	

	jQuery("#search-text").hover(
		function() {
			jQuery("#header #categories-navigation li .menu").hide();	
			jQuery("#header #categories-navigation li").removeClass("hover");	
		},
		function() { }
	);

});
var img_processing = new Image();	// Preload 'Processing' button image
img_processing.src = "includes/languages/english/images/buttons/button_secureLogin_1.gif";

// ------------------------------------------------------------------

function dbl_click_protect(){
	
	document.onkeypress = function(e){ var key = e ? e.which : window.event.keyCode; return (key != 13); };
	if(document.layers)	document.captureEvents(Event.KEYPRESS);
	
	// --------------------------------------
	
	var span_id;
	var $span_ref;
	
	var default_span	= "submitSpan";
	
	if(arguments.length==0){
		var spans	= Array(default_span);
	}
	else{
		var spans	= arguments;
	}
	
	for(var i = 0; i < spans.length; i++){
		span_id = spans[i];
		$span_ref = jQuery("#" + span_id);
		if($span_ref.length){
			$span_ref.html('<img src="' + img_processing.src + '" width="185" height="33" alt="Processing" title="Processing">');
		}
	}
	
	return true;
	
}

// ------------------------------------------------------------------

function addEvent(obj, evType, fn){ 
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if(obj.attachEvent){
		var r	= obj.attachEvent("on" + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function getSrcElement(e){
    var e = (window.event ? window.event : e);
    var src_element;
    if(e.target)                 { src_element = e.target; }
    else if(e.srcElement)        { src_element = e.srcElement; }
    if(src_element.nodeType==3)  { src_element = src_element.parentNode; }
    return src_element;
}

// ------------------------------------------------------------------

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +	( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// ------------------------------------------------------------------

function preloadImages(){
    if(!document.createElement){
        return false;
    }
    var preloadedImages = [];
    for(var i = 0; i < arguments.length; i++){
        preloadedImages[i] = document.createElement('img');
        preloadedImages[i].setAttribute('src', arguments[i]);
    }
}

// ------------------------------------------------------------------

jQuery(document).ready(function(){
    
    // Handle setting and clearing of search box default text
    var defaultSearchText   = "Keyword or Model #";
    var $searchText         = jQuery("#search-text");
    if($searchText.length){
        
        // Set default field value
        $searchText.val(defaultSearchText);
        
        // Setup autocomplete for search field
        $searchText.autocomplete("/helpers/autocomplete.php", {
            max: 5,
            delay: 100,
            minChars: 2,
            dataType: "json"
        });
        
        // Clear field value onfocus
        $searchText.focus(function(){
           var $elmt = jQuery(this);
           $elmt.addClass('focused');
           var searchValue = $elmt.val();
           if(searchValue==defaultSearchText){
               $elmt.val('');
           }
        });
        
        // Set default field value if no search term has been input
        $searchText.blur(function(){
            var $elmt = jQuery(this);
            $elmt.removeClass('focused');
            var searchValue = $elmt.val();
            if(searchValue != defaultSearchText && searchValue==''){
                $elmt.val(defaultSearchText);
            }
        });
        
        // Handle checking of search form
        jQuery("#search-products").submit(function(){
            var searchValue = $searchText.val();
            if(searchValue==defaultSearchText || searchValue==''){
                alert('Please enter keywords or a product model number to search for.');
                return false;
            }
            else{
                return true;
            }
        });
    }
    
});
