/*
*  drop down navbar  
*/
jQuery(document).ready(function() {
	jQuery("#navbar ul.primary > li.menu").hover(function(){
		jQuery(this).children("h2").addClass("active");
		jQuery(this).children("ul").show();
	},function(){
		jQuery(this).children("h2").removeClass("active");
		jQuery(this).children("ul").hide();
	});
});


/*
*  header links menu  
*/
jQuery(document).ready(function() {
	jQuery("ul#headerarea-links > li.menu").hover(function(){
		jQuery(this).children("a").addClass("active");
		jQuery(this).children("ul").show();
	},function(){
		jQuery(this).children("a").removeClass("active");
		jQuery(this).children("ul").hide();
	});
});


/*
*	fire up jquery-ui elements
*/
jQuery(document).ready(function(){
	jQuery(".tabs").tabs({ fx: { opacity: 'toggle' } });
	jQuery(".balloon-tabs").tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	jQuery("#home-slide").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 5000, false);
	jQuery("#sitesearch select").selectmenu({ style: 'dropdown' });
});


/*
*	recreate accordion
*/
jQuery(document).ready(function(){
	// initialize accordion
	jQuery(".accordion div").hide();

	// click event 
	jQuery(".accordion h3").click(function(e){
		e.preventDefault();
		jQuery(this).toggleClass("active")
			.next().toggleClass("active").slideToggle("fast");
	});
});


/*
*	leftnav
*/
jQuery(document).ready(function(){
	// initialize
	jQuery("#sidebar-left .nav div").hide();
	jQuery("#sidebar-left .nav h3.sub a").before("<span>&nbsp;</span>");
	// click event 
	jQuery("#sidebar-left .nav h3 span").click(function(){
		jQuery(this).parent().toggleClass("active")
			.next().toggleClass("active").slideToggle("fast");
	});
	
	// finds the current link
	var mycurrentlocation;
	var levels = jQuery("#breadcrumb-share span span a");
	if(levels.length > 3){
		mycurrentlocation = levels.eq(3).attr("href");
	}else{
		mycurrentlocation = window.location.pathname;
		var currenth3link = jQuery("#sidebar-left .nav h3 a[href^='"+mycurrentlocation+"']").parent();
		currenth3link.addClass("active");
		if(currenth3link.hasClass("sub")) {
			currenth3link.next().addClass("active").show();
		}
	}
	jQuery("#sidebar-left .nav div ul li a[href^='"+mycurrentlocation+"']")
		.parent().addClass("active")
		.parent().parent().addClass("active").show()
		.prev().addClass("active");
	
});


/*
*	popular searches box
*/
jQuery(document).ready(function(){
	// generate tags
	jQuery(".popularsearches-box .box-inner ul").wrap('<div class="expanding"></div>')
		.parent().parent().append('<a class="toggle-button" href="#">toggle</a>');
	
	var openheight = jQuery(".popularsearches-box .box-inner ul").height();
	var closedheight = 135;
	
	jQuery(".popularsearches-box .box-inner .expanding").css("height", closedheight);
	jQuery(".popularsearches-box .box-inner .toggle-button").toggle(function(){
		jQuery(this).css("background-position", "0 -20px")
			.prev().animate({ height : openheight });
			
	},function(){
		jQuery(this).css("background-position", "0 0")
			.prev().animate({ height : closedheight });
	});
});


/*
*	call Back to Top button in inner pages
*/
jQuery(document).ready(function(){
	if (window.location.pathname != "/Pages/default.aspx") {
		jQuery("head").append('<script type="text/javascript" src="/Style Library/MOM MasterPage/scrolltopcontrol.js"');	
	}
});

/*
        *  Rotating banners
        */ 
        function rotateBanner(){
        	jQuery("#home-banners .rotating-banners-panel a:first").animate({
        		marginLeft: "-240"
        	}, {
        		queue: false, 
        		duration: 800,
        		complete: function(){
        			jQuery("#home-banners .rotating-banners-panel").append(
        				jQuery(this).detach().css({ marginLeft: "0" })
        			);	
        		}
        	});
        }
		
 jQuery(document).ready(function(){
	//setInterval(rotateBanner, 3000);
	
	var slideshow = setInterval(rotateBanner, 3000);
	$linkPlayPause = jQuery('#PlayPause');
	$playcontrol = jQuery('#ImgPlayPause');
	// Play Control
			$(this).mouseover(function() { $("#ImgPlayPause").css("cursor", "hand");
                });
			$(this).mouseout(function() { $("#ImgPlayPause").css("cursor", "pointer");
				});
			
        	$playcontrol.click(function(e){
        	  var $this = $(this);
			  if($this.hasClass("paused")){
        	    slideshow = setInterval(rotateBanner, 3000);
        	    $this.removeClass("paused");
				$linkPlayPause.removeClass("paused").text("Pause");
				$(this).attr("src","~/_layouts/MOM/images/Pause-icon.png");
				$(this).attr("alt","Pause Icon");
				rotateBanner();
        	  }else{
        	    clearInterval(slideshow);
        	    $this.addClass("paused");
				$linkPlayPause.addClass("paused").text("Play");
				$(this).attr("src","~/_layouts/MOM/images/Play-icon.png");
				$(this).attr("alt","Play Icon");
        	  }
        	  });
			  
			  
			  $linkPlayPause.click(function(e){
        	  var $this = $(this);
			  if($this.hasClass("paused")){
        	    slideshow = setInterval(rotateBanner, 3000);
        	    $this.removeClass("paused").text("Pause");
				$playcontrol.removeClass("paused");
				$playcontrol.attr("src","~/_layouts/MOM/images/Pause-icon.png");
				$playcontrol.attr("alt","Pause Icon");
        	    rotateBanner();
        	  }else{
        	    clearInterval(slideshow);
        	    $this.addClass("paused").text("Play");
				$playcontrol.addClass("paused");
				$playcontrol.attr("src","~/_layouts/MOM/images/Play-icon.png");
				$playcontrol.attr("alt","Play Icon");
        	  }
			  e.preventDefault();
        	  });
		
});
