//handle external links
//Enter "_blank" for new window (each time), "window2" for a set secondary window
var newwindow="_blank"

function hyperlinks(target){
   //if(lang == null) lang = "en-US";
   var DomainArray = new Array("alcancable.biz","alcancable.cn","alcancable.com","alcancable.info","alcancable.net","Alcanshidehejin.com.cn","cablealcan.cn","cablealcan.com",
"cablealcan.com.cn","cablealcan.net","cabledealer.biz","cabledealer.com","cabledealer.info","cable-mall.biz","cable-mall.com","cable-mall.info",
"cnalcancable.com","cncablealcan.com","cnsaidehejin.com","cnsaidehejin.net","PreWiredSystems.net","saidehejin.cn","saidehejin.com","saidehejin.com.cn",
"saidehejin.net","saidehejin.net.cn","shidehejin.cn","shidehejin.com.cn","shidehejin.net.cn","stabiloy.com","stabiloychina.cn","stabiloychina.com",
"stabiloychina.com.cn","stabiloycn.cn","stabiloycn.com","stabiloycn.com.cn","stabiloyshidehejin.com","wire-mall.biz","wire-mall.com","wire-mall.info",
"modexproducts.com","modexmodularwiring.com","modexprefab.com","modexwiring.cn","modexwiringsystems.cn","modexsystems.cn","modexmodularwiring.cn","modexwiring.com","modexwiringsystems.com","stabiloy.org.mx");
   
   
   var outLink = "/cablepublic/legaldisclaimeroutsidelinks.aspx?Url=";
   if (target) where = newwindow;
   else where = "_top";
	for (var i=0; i<=(document.links.length-1); i++){
		var linkobj=document.links[i].href
		DocURL = linkobj;
		if(DocURL.substring(0,1) != "/"){
		        // custom		
		        protocolIndex=DocURL.indexOf("://",4);
		        serverIndex=DocURL.indexOf("/",protocolIndex + 3);
		        BeginURL=DocURL.indexOf("#",1) + 1;
		        urlresult=DocURL.substring(BeginURL,serverIndex);
		        displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
        		
			        if((displayresult.indexOf("alcan.com") == -1) && (displayresult.indexOf("cable.alcan.com") == -1)&& (displayresult.indexOf("accural.com") == -1) && (displayresult.indexOf("alcancable.com") == -1) &&(displayresult.indexOf("prewiredsystems.net")== -1)&&(displayresult.indexOf("localhost") == -1)&& (displayresult.indexOf("alcan.com") == -1) &&(displayresult.indexOf("atl-cabledev01") == -1)&&(displayresult.indexOf("atl-cabledev02") == -1)&&(displayresult.indexOf("atl-cablestg01") == -1))
			        {
			            var bLeave = false;
        				
        				for (var s = 0; s < DomainArray.length; s++){ 
                              if(displayresult.indexOf(DomainArray[s]) != -1) {
                              bLeave = true;
                              break;
                              }
                          } 
                        if(!bLeave){
				        if ( linkobj.indexOf("javascript:") ==-1 && linkobj.indexOf("#") ==-1 && linkobj.indexOf("mailto:") ==-1)
				        {
   					        //if (target && where!="_blank") //DynamicDrive.com added routine- open window in set secondary window
           						
      					        document.links[i].onclick=function(){
							        if (window.window2 && !window2.closed)
							        window2.location= outLink + encodeURIComponent(this.href) ;
							        else
        					        window2=window.open(outLink + encodeURIComponent(this.href));
							        window2.focus()
      						        return false
      							        }
   				        //	else{
   				        //		//alert(linkobj);
      			        //		if (newwindow=="window2") document.links[i].onclick = "";    
      			        //		document.links[i].target = where;
       			        //		}
   				        }
   				        }
			        }
			        if(linkobj.indexOf("mms://") != -1)
			        {

				        link = "/alcancable/includes/playmedia.asp?movie=" +  encodeURIComponent(linkobj) + "." ;
        				
				        document.links[i].onclick=function(){
						        window.showModalDialog(link,"", "scroll:no;dialogHeight:575px;dialogWidth:663px;center:yes;resizable:no;status:no;"); 
      					        return false
      						        }
			        }
			        if ((linkobj.indexOf(".pdf") !=-1) || (linkobj.indexOf(".doc") !=-1))
			        {
   				        if (target && where!="_blank") 
      				        document.links[i].onclick=function(){
						        if (window.window2 && !window2.closed)
							        window2.location=this.href
						        else
        					        window2=window.open(this.href)
							        window2.focus()
      						        return false
      						        }
   				        else{
      				        if (newwindow=="window2") document.links[i].onclick = "";    
      				        document.links[i].target = where;
       				        }
   			        }
		    }
			
		}
}

function inithyperlinks(){    //DynamicDrive.com added routine
	hyperlinks(true)
}

window.onload=inithyperlinks
/***************************************************/

jQuery(function() {
    jQuery("#language_chooser").dropdown({
        depth: 2,
        width: 215,
        padding: 11
    });
    jQuery("#market-select").dropdown({
        depth: 1,
        width: 184,
        padding: -5
    });

    jQuery("#contact ul").each(function() {
        var list = jQuery(this);
        var id = jQuery(this).attr("id").replace(/_list/, "");
        var anchor = jQuery("#"+id);

        list.hover(function() {
            anchor.addClass("active");
        }, function() {
            anchor.removeClass("active");
            list.hide();
        });
        anchor.hover(function() {
            list.show();
        }, function() {
            setTimeout('if (!jQuery("#'+id+'").hasClass("active")) {jQuery("#'+id+'_list").hide();}', 50);
        });
    });

    jQuery("#search_field").focus(function() {
        if (jQuery(this).val().toLowerCase() == "search the site") {
            jQuery(this).val("");
        }
        jQuery(this).addClass("active");
    }).blur(function() {
        if (jQuery(this).val() == "") {
            jQuery(this).val("Search the site");
        }
        jQuery(this).removeClass("active");
    });

	jQuery("#left-bar .box > div > h3").click(function() {
		var parent = $(this).parent();
		if (parent.hasClass("active")) {
			parent.removeClass("active");
		} else {
			parent.addClass("active");
		}
	}).hover(function() {
		$(this).parent().addClass("hover");
	}, function() {
		$(this).parent().removeClass("hover");
	});

    // Mouse over handling for IE 6
    if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
        jQuery("#top_bar #contact > a, #top_bar #access_alcan, #main_nav > li").hover(function() {
            jQuery(this).addClass("hover active");
        }, function() {
            jQuery(this).removeClass("hover active");
        });
        jQuery("#top_bar #contact ul").each(function() {
            jQuery(this).children("li:first").css("margin-top", 0);
        });

		if (jQuery("#content").hasClass("with-both")) {
	        var height = 0;
	        var left_height = jQuery("#content #left-bar").height();
	        var body_height = jQuery("#content #body").height();
	        var right_height = jQuery("#content #right-bar").height();
	
	        if (left_height > height) height = left_height;
	        if (body_height > height) height = body_height;
	        if (right_height > height) height = right_height;
	
	        jQuery("#content, #content>div").height(height);
        }
    }
});

(function($) {
    // IE has problems with background-position. This function takes care of it
    jQuery.fn.backgroundPosition = function(v) {
        var p = $(this).css("background-position");
        if (!v) {
            if (typeof(p) == "undefined") {
                return $(this).css("background-position-x") + " " + $(this).css("background-position-y");
            } else {
                return p;
            }
        } else {
            if (typeof(p) == "undefined") {
                v = v.split(" ");
                $(this).css("background-position-x", v[0])
                    .css("background-position-y", v[1]);
            } else {
                $(this).css("background-position", v);
            }
            return this;
        }
    };
})(jQuery);

/**
 * Retrieve a parameter from the page URI. If the parameter is registered
 * without a value then true is returned.
 *
 * @param  name  string  The name of the parameter
 */
getParameter = function(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

    var regexS = "[\\?&]"+name+"(=([^&#]*))?";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);

    if (results == null) {
        return null;
    } else {
        return results[2] || true;
    }
};

