﻿jQuery(function() {
	if (IsHomepage) {
	    //will work only for the visible divs

    	$('div.hpPersonDescr').jScrollPane();

		//enable slideshow
		$("ul.slideShow").slideShow({
		    index: "div.slideShowIndex",
			time: 10000
		});
		
		//enable tabs on homepage
		
		 $("div.TabBox").makeTabs1({
		    tab: "div.TabClickable",
        tabs: "ul.Tabs",
        content: "div.TabContent",
        contents: "ul.TabContents",
        current: "TabSelected", 
        curIndex:1, // you can set any tab open when page loads
        onShow:function(curTab, curTabContent){
          curTabContent.jScrollPane();
        }
    }); 
	}
	try {
		if (IsHomepage) {
			$("div.primarynavigation ul.topnav li div.SectionNavigatorMenu").show();
			ifIE6fixPngBgWithDiv("div.primarynavigation"); //fix background image for top navigator
		} else {
		    var fixHeight = 124;
		    function useHeight(height) {
		        return fixHeight//height;
		    }
               function rollIn() {
                var a = $(this).find("a.SectionNavigatorMenuArrow");
                var img = a.find("img");
                var srcAttr = img.attr("src").indexOf("arrow_") >= 0 ? img.attr("src") : img[0].style.filter;
                var div = a.find("+div.SectionNavigatorMenu");
                if (srcAttr && srcAttr.indexOf("arrow_down") == -1) {
                  img.attr("src", "/images/arrow_down.png");
                  ifIE6fixPngImg(img);
                }
                var isVisible = div.is(':visible');
                if (isVisible)
                  //div.stop().animate({ height: 10 }, 450, function() { $(this).css("display", "none"); });
                  
                return false;
              }
              
              function rollOut() {
                var a = $(this).find("a.SectionNavigatorMenuArrow");
                var img = a.find("img");
                var srcAttr = img.attr("src").indexOf("arrow_") >= 0 ? img.attr("src") : img[0].style.filter;
                var div = a.find("+div.SectionNavigatorMenu");
                /*img.click(function(){
                img.parents('li').children('.SectionNavigatorMenu').stop(true, true).slideToggle(400);
                })
                  */
                if (srcAttr && srcAttr.indexOf("arrow_down") >= 0) {
                  img.attr("src", "/images/arrow_up.png");
                  ifIE6fixPngImg(img);
                }
                var isVisible = div.is(':visible');
                if (!isVisible)
                  //div.stop().animate({ height: useHeight(div.children().height()) + 40 }, 500, "swing");
                return false;
              }
              function rollOverMenu() {
                var a = $(this);
                var img = a.find("img");
                var srcAttr = img.attr("src").indexOf("arrow_") >= 0 ? img.attr("src") : img[0].style.filter;
                var div = a.find("+div.SectionNavigatorMenu");
                if (srcAttr) {
                  if (srcAttr.indexOf("arrow_down") >= 0)
                    img.attr("src", "/images/arrow_up.png");
                  else
                    img.attr("src", "/images/arrow_down.png");
                  ifIE6fixPngImg(img);
                }
                var isVisible = div.is(':visible');
                if (isVisible) {
                  //div.animate({ height: 10 }, 500, function() { $(this).css("display", "none"); });
                  //div.animate({ height: 10 }, 500, function() { $(this).slideUp(); });
                } else {
                  //div.show().animate({ height: useHeight(div.children().height()) + 10 }, 500, "swing");
                }
                return false;
              }
             
             jQuery(function(){
                $('.tryIt').each(function(){
                    var root = $(this);
                    var snm = root.parents().children('.SectionNavigatorMenu');
                    root.parents('li').mouseenter(function(){
                        snm.stop(true, true).slideDown(400);
                    });
                    root.parents('li').mouseleave(function(){
                        snm.slideUp(400);
                    });
                });
             })


            ifIE6fixPngBgWithDiv("div.topNavigator ul.topnav");
			$("div.topNavigator ul.topnav li a.navLink").each(function() {
				var elem = $(this);
				elem.after("<a class='SectionNavigatorMenuArrow' href=\"javascript:void(0);\"><img src='/images/arrow_down.png'></a>");
			});
			ifIE6fixPngImg('a.SectionNavigatorMenuArrow img');
			//$('a.SectionNavigatorMenuArrow').click(rollOverMenu);
			$("div.topNavigator ul.topnav li").hover(rollOut, rollIn);
		}
	} catch (e) { alert(e.message); }

	//when window is resized, make sure that the footer and header have the correct width
	$(window).resize(function() {
		var prevWidth = -1;
		function resizeTB() {
			var prefWidth = 1004;
			var header = $("#header");
			var footer = $("#footer");
			if (header.width() < prefWidth)
				header.width(prefWidth);
			if (footer.width() < prefWidth)
				footer.width(prefWidth);
			var ww = $(window).width();
			if (ww > prefWidth) {
				header.width(ww);
				footer.width(ww);
			}
			if (ww != prevWidth) {
				prevWidth = ww;
				window.setTimeout(resizeTB, 200);
			}
		}
	});
});

jQuery(function(){
/* Menu Tooltips */

$('div.topNavigator li.MenuListItem0 a[title]').qtip({   
		 style: {
			 name: 'dark',
			 background:'transparent',
			 border: '0',
			 color: '#000',
			 padding: '5px 0 5px 3px'
		 },
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
		 width: { 
		 	min: 205
		},
		position: {
			corner: {
				target: 'leftMiddle',
				tooltip: 'rightMiddle'
			},
		adjust: { x: 28, y: 2 }
		}
	});
	
});

jQuery(function() {
/* For Homepage navigator*/
$('div.primarynavigation li.MenuListItem0 a[title]').qtip({   
		 style: {
			 name: 'dark',
			 background:'transparent',
			 border: '0',
			 color: '#000',
			 padding: '5px 0 5px 3px'
		 },
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
		 width: { 
		 	min: 205
		},
		position: {
			corner: {
				target: 'leftMiddle',
				tooltip: 'rightMiddle'
			},
		adjust: { x: 28, y: 2 }
		}
	});
	
});

jQuery(function(){
    $("img.videoIconImg").reflect({ height: 0.65 });
    $("a.ShowVideoEmbedded").colorbox();    
});



// styling the topnav last item for IEs
$(document).ready(function(){
$('div.topNavigator ul.topnav li:last').css('margin-right', '0')
});
