﻿// jQuery INITIALIZATIONS BLOCK 
$(document).ready( function() {

//Show the control panel if we have a site actions menu present
    if (document.getElementById("siteactiontd").childNodes.length > 1) {
    	$("#siteActionsPanel").css("display","block");
    }


// jQuery Cycle Initialization for Featured Content 	
//Create control panel

	if ($("#featuredContent li").length > 1){  //if more than one featured item, build the nav and start the rotation.
	
		$('#featuredContent').after('<div id="controlPanel">');

//Build the control panel
		var $prev = "<a href=\"#\" id=\"prevImg\"><img src=\"/SiteCollectionImages/prevbutton.jpg\" alt=\"Go to previous image\" border=\"0\" /></a>";
		var $nav = "<div id=\"contentNav\"></div>"
		var $play = "<a href=\"#\" id=\"playImg\"><img src=\"/SiteCollectionImages/playbutton.jpg\" alt=\"Play slideshow\" border=\"0\" /></a>";
		var $pause = "<a href=\"#\" id=\"pauseImg\"><img src=\"/SiteCollectionImages/pausebutton.jpg\" alt=\"Pause slideshow\" border=\"0\" /></a>";
		var $next = "<a href=\"#\" id=\"nextImg\"><img src=\"/SiteCollectionImages/nextbutton.jpg\" alt=\"Go to next image\" border=\"0\" /></a>"
		$('#controlPanel').append($prev).append($nav).append($play).append($pause).append($next);

//Attach Play and Pause functionality 
		$('#playImg').click( function() {
			$('#playImg').hide();
			$('#pauseImg').show();
			$('#featuredContent').cycle('resume');
			return false;
		});
		$('#pauseImg').click( function() {
			$('#pauseImg').hide();
			$('#playImg').show();
			$('#featuredContent').cycle('pause');
			return false;
		});
					
//Set Cycle customizations
		$('#featuredContent')
		.cycle({
						fx: 'fade',
						speed: 500,
						timeout: 7000,
						pager : '#contentNav',
						next: '#nextImg',
						prev: '#prevImg'

		});
		
//Center the featured nav
		var featureWidth = $("#featuredContent").width();
		var navWidth =  $("#controlPanel").width();
		var ctr = parseInt((featureWidth - navWidth)/2 );
		$("#controlPanel").css("left", ctr + "px");
	}
				

// jQuery Superfish Menu Initialization 			
	$('ul.KI-Menu').superfish({
		autoArrows:	true,
		onShow: function(){
			if(($(this).offset().left + $(this).outerWidth()) > $("body").outerWidth()) {
				$(this).css("left", "-" + $(this).parent().outerWidth() + "px");
			}
		}
	});
	
	if ( !$("#relativeContentArea > div").has("*").length ){
		$("#relativeContentArea").css("display","none");
	}

			
});





