//**************************************************
$(document).ready(function(){
	document.search_form.search_str.focus();
 // field.form.elements[next].focus();
 
	$(".colorBoxFrameWindow").colorbox({iframe:true, innerWidth:'1006', innerHeight:'300', top:'20px'}); //for log in popup
});
//**************************************************
    /*$(document).ready(function() {
			
            //When page loads...
       
		    $(".tab_content").hide(); //Hide all content
            $("ul.tabs li:first").addClass("active").show(); //Activate first tab
            $(".tab_content:first").show(); //Show first tab content

            //On Click Event
            $("ul.tabs li").click(function() {

                $("ul.tabs li").removeClass("active"); //Remove any "active" class
                $(this).addClass("active"); //Add "active" class to selected tab
                $(".tab_content").hide(); //Hide all tab content


                var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content


			   if (activeTab=="#handtool_items"){
			 		$(".tommywalsh").show();
			   }else{
			   		$(".tommywalsh").hide();
			    }


			    $(activeTab).show(); //Fade in the active ID content
                return false;
            });

                $("#slider").easySliderReverse({
                        controlsBefore:	'<p id="controls">',
                        controlsAfter:	'</p>',
                        auto: false,
                        continuous: false
                    });
                    $("#slider2").easySliderV2({
                        controlsBefore:	'<p id="controls2">',
                        controlsAfter:	'</p>',
                        prevId: 'prevBtn2',
                        nextId: 'nextBtn2',
						height:595
                    });
     			   });
			*/    

//**************************************************
 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17787332-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  //**************************************************
  		$(document).ready(function() {

            var menuCache = new Array();
            var menuDiv = new Array();
            var current = new Array();
            var twidth = new Array();
            var mtimer = null;
            var isover = false;
            var ttop = new Array();
            var clevel = 0;
            var maxitems = 14;
            var sinterval = null;
            /* Change this config to change the menu behaviour */
            var menuConfig = {
                duration : 300, // scrolling animation duration in miliseconds
                delay: 0, //animattion delay for successive call for scroll,
                rows: 10, //rows to be moved for single click
								hoverDelay: 450
            };
            var mouseConfig = {
                x :0 ,
                y :0
            };

            var menuItem = function(li, ul){
                this.li = li;
                this.ul = ul;
                this.div = null;
								this.width = 0;
                return this;
            };

            var showMenu = function(lthis) {
                reset(true, true);
                hideMenu();
                isover = true;
                var s = $(lthis).attr('id').split("_");
                clevel = s.length - 2;
                var id = parseInt(s[1]);

                current[clevel] = menuCache[id].div;

                var pos = $(lthis).position();
                current[clevel].css({
                    left: pos.left,
                    top: pos.top + 30,
                    zIndex: clevel
                })
                .show();
                twidth[0] = pos.left;
                twidth[1] = current[clevel].width();

                ttop[0] = pos.top;
                ttop[1] = 30;
                $(lthis).find(".cmConID").show();
                //current[clevel].dropShadow({zindex: clevel});
            };

            var removeAll = function(start, equal){
                //return;
                var id = "", cid = "";
                for(var i = start; i < current.length; i++){
                    if(current[i] !== null && typeof(current[i]) !== 'undefined'){
                        id = $(current[i]).attr('id');
                        cid = id + "";
                        $("li#"+cid.substring(4, cid.length)).removeClass("li_hover");
                        current[i].hide();
                        //current[i].removeShadow();
                    }
                    current[i] = null;
                }
            };

            var reset = function(ctim, cint){
                if(cint){
                    if(sinterval !== null){
                        clearInterval(sinterval);
                        sinterval = null;
                    }
                }
                if(ctim){
                    if(mtimer !== null){
                        clearInterval(mtimer);
                        mtimer = null;
                    }
                }
            };

            var hideMenu = function() {
                $(".cmConID").hide();
                reset(true, false);
                removeAll(0,false);
            };

						var highlight = function(splits){
							var name = "";
							name = splits[0]+"_"+splits[1];
							for(var i = 2; i < splits.length; i++){
								name += "_" + splits[i];

								$("li#"+name).addClass("li_hover");
							}
						};

            var showMenuV2 = function(lthis) {
                reset(false, true);
                isover = true;

                var s = $(lthis).attr('id');
                var splits = s.split("_");
                clevel = splits.length - 2;

                if(current[clevel] !== $("#div_" + s)){

                    reset(true, false);
                    removeAll(clevel, false);
										highlight(splits);
                    current[clevel] = $("#div_" + s);
                    var tt = 0;
                    for(var i = 0; i <= clevel; i++){
                        tt += twidth[i];
                    }

										//add width calculation


                    twidth[clevel+1] = $(current[clevel]).width();
                    var pos = $(lthis).position();
                    ttop[clevel+1] = pos.top + 5;
                    var tp = 0;
                    for(var i = 0; i <= (clevel + 1); i++){
                        tp += ttop[i];
					}

                    current[clevel].css({
                        'left': tt - 5,
                        'top': tp,
                        'zIndex': clevel
                    }).show();
                    //current[clevel].dropShadow({zindex: clevel});
                }
            };

            var hideMenuV4 = function(lthis) {
                reset(false, true);
                isover = true;

                var s = $(lthis).attr('id');
                var splits = s.split("_");
                clevel = splits.length - 2;

                if(current[clevel] !== $("#div_" + s)){
                    reset(true, false);
                    removeAll(clevel, true);
                }
            };

						var hideMenuV5 = function(s) {
                reset(true, false);
                var splits = s.split("_");
                var level = splits.length - 2;
                removeAll(level + 1,false);
            };

            var hideMenuV2 = function(lthis) {
                reset(true, false);
                var s = $(lthis).attr('id');
                var splits = s.split("_");
                var level = splits.length - 2;
                removeAll(level,false);
            };

            var hideMenuV3 = function(lthis) {
                reset(true, false);
                var s = $(lthis).attr('id');
                var splits = s.split("_");
                var level = splits.length - 2;
                removeAll(level+1,false);
            };

            var buildItemV2 = function(item, tag) {
               var li = $(document.createElement("li"));
				$(item).attr('id', tag);
				$(li).attr('id', tag);
				var cc = $(item).find("a").first().html();
				cc = cc.replace(/^\s+|\s+$/g, "");
							cc = cc.replace(/\s+/g,"&nbsp;");
				$(item).find("a").first().html(cc);
				li.html("<div class='div_li_menu' style='width:100%;padding-right: 50px;'><a class='div_li_menu_a' href='"+$(item).find("a").first().attr('href')+"'>"+cc+"</a></div>");
				li.height(22);
				return li;
            };

            var buildCacheV2 = function(lthis, tag,  level, index) {
                var items = $(lthis).find("ul.cmenu").find("li." + (level + 1));
                var cache = null;
                if (items.length > 0) {
                    cache = new Array();
                    for (var i = 0; i < items.length; i++) {
                        cache[i] = buildCacheV2(items[i], tag + "_" + i, level + 1, i);
                    }
                    var item =  new menuItem(buildItemV2(lthis, tag),cache);
                    item.li.addClass("more");
                    return item;
                }

                return new menuItem(buildItemV2(lthis, tag),null);
            };

            var showHide = function(menu, tthis, tmid){
                if(tmid.scrollTop() + tmid.height() + 22 >= (menu.ul.length * 22)){
                    $(tthis).parent().find(".down").css('opacity',0.2);//.hide();
                    reset(false, true);
                }else{
                    $(tthis).parent().find(".down").css('opacity',1.0);
                }

                if(tmid.scrollTop() <= 22){
                    $(tthis).parent().find(".up").css('opacity',0.2);//.hide();
                    reset(false, true);
                }else{
                    $(tthis).parent().find(".up").css('opacity',1.0);
                }
            };

            var moveMenu = function(tthis, menu, config, direction, event){
                isover = true;
                reset(false, true);
                var tmid = $(tthis).parent().find(".mid");
                hideMenuV3(menu.li);
                var isdown = false;
                switch(event){
                    case 'down':
                        isdown = true;
                        switch(direction){
                            case 'down':
                                tmid.animate({
                                    scrollTop: tmid.scrollTop() + (config.rows * 22)
                                }, config.duration,'linear',
                                function(){
                                    showHide(menu, tthis, tmid);
                                });
                                sinterval = setInterval(function(){
                                    tmid.animate({
                                        scrollTop: tmid.scrollTop() + (config.rows * 22)
                                    }, config.duration,'linear',
                                    function(){
                                        showHide(menu, tthis, tmid);
                                        if(!isdown){
                                            reset(false, true);
                                            return;
                                        }
                                    });
                                }, config.duration + config.delay);
                                break;
                            case 'up':
                                tmid.animate({
                                    scrollTop: tmid.scrollTop() - (config.rows * 22) > 0 ? tmid.scrollTop() - (config.rows * 22) : 0
                                }, config.duration,'linear',
                                function(){
                                    showHide(menu, tthis, tmid);
                                });
                                sinterval = setInterval(function(){
                                    tmid.animate({
                                        scrollTop: tmid.scrollTop() - (config.rows * 22) > 0 ? tmid.scrollTop() - (config.rows * 22) : 0
                                    },config.duration,'linear',
                                    function(){
                                        showHide(menu, tthis, tmid);
                                        if(!isdown){
                                            reset(false, true);
                                            return;
                                        }
                                    });
                                },config.duration + config.delay);
                                break;
                        }
                    break;
                case 'up':
                    isdown = false;
                    break;
                }
            };

						var calculateWidth = function (text){

						};



            var buildMenuDiv = function(menu){
                if(menu.ul !== null){
                    var tChar = 0;
                    var maxChar = 0;
                    var bottom = $(document.createElement("div")).height(20).addClass("down")
																.hover(function(){
																		hideMenuV5($(this).attr('tag'));
																})
                                .mousedown(function(){
                                    moveMenu(this, menu, menuConfig, 'down', 'down');
                                })
                                .mouseup(function(){
                                    moveMenu(this, menu, menuConfig, 'down', 'up');
                                })
                                .mouseleave(function(){
                                    isover = false;
                                    //reset(false, true);
																		reset(true, false);
																		var tthis = this;
																		mtimer = setInterval(function(){
																				if(isover == false){
																						hideMenuV5($(tthis).attr('tag'));
																						hideMenu();
																				}
																		}, menuConfig.hoverDelay);
                                })
																.attr('tag',menu.li.attr('id'));
                    var up  = $(document.createElement("div")).height(20).addClass("up")
																.hover(function(){
																		hideMenuV5($(this).attr('tag'));
																})
                                .mousedown(function(){
                                    moveMenu(this, menu, menuConfig, 'up', 'down');
                                })
                                .mouseup(function(){
                                    moveMenu(this, menu, menuConfig, 'up', 'up');
                                })
                                .mouseleave(function(){
                                    isover = false;
																		reset(true, false);
																		var tthis = this;
																		mtimer = setInterval(function(){
																				if(isover == false){
																						hideMenuV5($(tthis).attr('tag'));
																						hideMenu();
																				}
																		}, menuConfig.hoverDelay);
                                }).css('opacity',0.2)
																.attr('tag',menu.li.attr('id'));
                    var ul = $(document.createElement("ul")).addClass("tcmenu");
                    var mid = $(document.createElement("div")).css({
                                float: 'left',
                                height: ((maxitems > menu.ul.length ? menu.ul.length : maxitems) * 22)  + 'px',
                                overflow: 'hidden'
                            }).attr('class',"mid");
                    var div = $(document.createElement("div")).addClass("cdiv").css({
                                'left': '0px'
                            }).attr('id',"div_" + menu.li.attr('id'));
                    mid.append(ul);

                    for(var i = 0; i < menu.ul.length; i++){
                        menu.ul[i].div = buildMenuDiv(menu.ul[i]);
                        $("#menu_overlay").append(menu.ul[i].div);
                        tChar = menu.ul[i].li.find(".div_li_menu").find("a").html();
						tChar = tChar.replace(/^\s+|\s+$/g, "");
						tChar = tChar.replace(/\n*/i," ");
						tChar = tChar.replace(/\s+/i," ");
                        $(ul).append(menu.ul[i].li);
                        maxChar = tChar.length > maxChar ?  tChar.length: maxChar;
                        if(menu.ul[i].ul !== null && menu.ul[i].ul.length > 0){
                            $(menu.ul[i].li).hover(function(e){
																reset(true, false);
                                showMenuV2(e.currentTarget);
                            });
                        }else{
                            $(menu.ul[i].li).hover(function(e){
																//reset(true, false);
                                //showMenuV2(e.currentTarget);
																hideMenuV2(e.currentTarget);
                            });
                        }
                        $(menu.ul[i].li).mouseleave(function(e){
                            isover = false;
														reset(true, false);
                            mtimer = setInterval(function(){
                                if(isover == false){
                                    hideMenuV2(e.currentTarget);
                                    hideMenu();
                                }
                            }, menuConfig.hoverDelay);
                        });
                    }
					var max = 250;

					for(var i = 0; i < menu.ul.length; i++){
						menu.ul[i].li.attr('tag', max);
					}


					mid.css('width', 'auto');

					if(maxitems >= menu.ul.length){
						up.css('background','none');
						up.height(10);
						up.css('opacity',0.2);
					}
					div.append(up);
					div.append(mid);

					if(maxitems >= menu.ul.length){
						bottom.css('background','none');
						bottom.height(10);
						bottom.css('opacity',0.2);
					}
					div.append(bottom);

                    return div;
                }
                return null;
            };

            var buildMenuV2 = function() {
                var menus = $("ul.ul_submenu").find("li.sub");
                for(var i = 0; i < menus.length; i++){
                   menuCache[i] = buildCacheV2(menus[i], "sub_" + i, 0, i);
                   $(menus[i]).append(menuCache[i]);
                   menuCache[i].div = buildMenuDiv(menuCache[i]);
                   buildHeader(menus[i],$(menus[i]).position());
                   $("#menu_overlay").append(menuCache[i].div);
                }
            };
            curvyCorners({
                tl: {
                    radius: 10
                },
                tr: {
                    radius: 10
                },
                bl: {
                    radius: 0
                },
                br: {
                    radius: 0
                },
                antiAlias: true
            },
            ".menu_div");

            var buildHeader = function(lthis, pos) {
                var header = $(document.createElement("div"))
                .attr('class', 'cmConID')
                .height(24).width($(lthis).width()).css({
                    'left': '0px',
                    'top': '-7px'
                }).addClass("cheader").html('<a href="'+ $(lthis).find("a").first().attr("href")+'">' +  $(lthis).find("a").first().html() + "</a>").hide();
                $(lthis).append(header);
                setCorners();

            };

            var setCorners = function() {
                curvyCorners({
                    tl: {
                        radius: 10
                    },
                    tr: {
                        radius: 10
                    },
                    bl: {
                        radius: 0
                    },
                    br: {
                        radius: 0
                    },
                    antiAlias: true
                },
                ".cmConID");
            };

            $("ul.ul_submenu").find("li.sub").hover(function() {
                showMenu(this);
            });
            $("ul.ul_submenu").find("li.sub").mouseleave(function() {
                isover = false;
                mtimer = setInterval(function(){
                    if(isover == false)
                        hideMenu();
                },menuConfig.hoverDelay);
            });
            buildMenuV2();
            //add mouse listener
            $(document).mousemove(function(e){
                mouseConfig.x = e.pageX;
                mouseConfig.y = e.pageY;
            });
        });
		
		   $(document).ready(function(){  
      
        $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
      
       
	var hover = false;
$("ul.secondnav > li > a").mouseover(function()
	{   
    
            //Following events are applied to the subnav itself (moving subnav up and down)  
            $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click 
			 
			hover = true;

       		 $(this).addClass("menu_black_tab");
			 $(this).css('color','#FFFFFF');
			
		
            $(this).parent().hover(function() {  
            }, function(){  

         		hover = false;

			    $(this).parent().find("ul.subnav").slideUp('slow',function() {
					if (!hover)
					{
	    				$('.login_menu').removeClass("menu_black_tab");
						$('.login_menu').css('color','#333');
					}	
  					}); 
					
		   });  
      
            //Following events are applied to the trigger (Hover events for the trigger)  
            }).hover(function() {  
                $(this).addClass("subhover"); //On hover over, add class "subhover"  
            }, function(){  //On Hover Out  
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"  
		
			//console.log('closed!!');*/
     });
	 
	 
	 	var hover = false;
		var clipboardopen = false;
$("ul.clipboardnav > li > a").click(function()
	{   
      if (hover == false){
            //Following events are applied to the subnav itself (moving subnav up and down)  
            $(this).parent().find("div.clipboard_curve_top").slideDown('slow'); 
			$(this).parent().find("ul.clipboardnav_mid").slideDown('fast').show(); //Drop down the subnav on click 
			$(this).parent().find("ul.clipboardnav_bottom").slideDown('fast').show(); //Drop down the subnav on click 
			 
			hover = true;

       		 $(this).addClass("clipboardnav_top_highlight");
			
			  $(".clipboard_count").addClass("clipboard_count_highlight");
			 $(this).css('color','#FFFFFF');
			  $(".clipboard_text").css('color','#FFFFFF');
			  
	  }else{
				
         		hover = false;
				$(this).parent().find("div.clipboard_curve_top").slideUp('slow'); 
			    $(this).parent().find("ul.clipboardnav_mid").slideUp('slow'); 
			   $(this).parent().find("ul.clipboardnav_bottom").slideUp('slow',function() {
					if (!hover)
					{
	    				$('.clipboardnav_top').removeClass("clipboardnav_top_highlight");
						$(".clipboard_text").css('color','#333');
					}	
  					   $(".clipboard_count").removeClass("clipboard_count_highlight");
					}); 
			
		
		  
      
            //Following events are applied to the trigger (Hover events for the trigger)  
         
	}
	});
	
	 });	
	 
	 
	 
//**************************************************



