
// JavaScript Document
$(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    6,   // minimum width of sub-menus in em units 
            maxWidth:    20,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({autoArrows:true});  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
						 
		//$('.scroll-pane').jScrollPane({scrollbarWidth:10,showArrows:false});
		
		//$('newsimage').click(function(){
		//		var img = $(this).attr("name");
		//		
		//});
		
		run_summary();
		
		/*
		$('.element')
		.before('<div id="pager">')
		.cycle({
			fx: 'fade',
			speed:  1000,
			//easing: 'easeOutQuad',
			pager: '#pager',
			timeout: 10000,
			pause: 1
		});
		*/
		//$('hr').attr("noshade","noshade");
		$(document).pngFix(); 
		
		$('#extra').hide();
		$('#extranav').hide();
		
		$('.showextra').click(function(){
			$('#quote').hide();		   	
			$('#extra').slideDown();	
			$('#extranav').slideDown();
			
		});
		
		$('.hideextra').click(function(){
			$('#extra').slideUp();	
			$('#extranav').slideUp();
			$('#quote').show();
		});

}); 

function show_pop(file){
	//Shadowbox.init({
	//	players:    ["iframe"]
	//});
	Shadowbox.open({
        content:    file,
        player:     "iframe",
        height:     370,
        width:      600
    });
	$('.tag').hide();
	return false;
}

function run_summary(){
	$('.summary').cycle({
			fx: 'scrollUp',
			speed:  1000,
			next: '#next',
			easing: 'easeOutQuad',
			timeout: 0
		});
}

function edit_content(cid,type,action){
	$('.summary').html("");
	$('.summary').load("content.php?cid="+cid+"&type="+type+"&Submit="+action,function(){
   			run_summary();
	 });
	
}

	
setTimeout("showtag()",500);
function showtag(){
	var currcss = $('.sf-menu a.current').attr("class");
	$('.sf-menu li.current').append("<span class='tag "+currcss+"'></span>");
	$('.tag').animate({height:"8px",bottom:"-8px"},600);
	showlisttag();
}

function showlisttag(){
	$('.listtag').animate({width: "11px",right:"-31px"},600);
}
	
function hidelisttag(){
	$('.listtag').animate({ width: "0px",right:"-20px"},600).remove();
	//setTimeout("",600);
}

function change_story(type,cid){
	$(".elementshell").load("element.php?type="+type+"&cid="+cid);
	//remove old list tag
	hidelisttag();
	//append to new div
	$("#item_"+cid).prepend("<span class='listtag'>&nbsp;</span>");
	//show new tag
	showlisttag()
	
	return false;
}

function toggleP(me,target) {
	$("#"+me).hide();	
	$("#"+target).fadeIn("slow");	
}
/*$(function() {
	$('.pics').cycle({
		timeout: 10000 ,	
		delay:  1000, 
		speed:  2000
		
	});
}); */

var nav = 
{
	dohover : function()	{
		
			var menuActive = false;
			var sunTimer;
			
			//$("ul.sf-menu li div.label").each(function()	{
			//	$(this).append("<span class='right'></span><span class='pointer'></span>");
			//});
			
			// position the pointer on the first and last

			//$("ul.sf-menu li:first-child div.label span.pointer").css("width",$("ul.sf-menu li:first-child div.label").attr("offsetWidth"));
			//$("ul.sf-menu li:last-child div.label span.pointer").css("margin-right","6px");
			
		
			$(".sf-menu li").mouseenter(function()	{
			
				$(this).stop(clearQueue=true);
				clearTimeout(sunTimer);
				//$("ul.sf-menu div.label:visible").css("visibility","hidden");
			
			
				if (!$(this).parent("li").hasClass("active"))	{
				//	// mouseover thhe non active item set variable to true and lower the active page
					menuActive = true
				//	$("ul.sf-menu li.active").children("a").append("<div class='hov'>&nbsp;</span>");
				//	$("ul.sf-menu li.active").children(".hov").animate({bottom: "0px"},200,"swing");
				}
							
				// animate the sun
				$(this).append("<span class='hov'>&nbsp;</span>");
				$(this).children(".hov").animate({bottom: "-2px"},200,"swing");
				
				// calculate where to position the label
				
				// get the width of the label, css visibility rather than display has to be used to calculate widths of hidden elements
				/*
				var labelWidth = $(this).prev("div.label").attr("offsetWidth");
				var labelLeft = 0;
				var sunWidth = 30;
				
				
				if ($(this).parent("li").is(":first-child"))	{
					//alert("first");
					labelLeft = labelLeft;
				}
				else if ($(this).parent("li").is(":last-child"))	{
					
					labelLeft = labelLeft-labelWidth;
					labelLeft = labelLeft+sunWidth;
					//hack
					labelLeft = labelLeft+15;
					
				}
				else if (labelWidth > 34)	{
					labelLeft = (labelWidth - sunWidth) / 2;
					
					//hack - fix me
					labelLeft = labelLeft - 5;
					labelLeft = Math.ceil(labelLeft);
					
					if (labelLeft < 0)	{
						labelLeft = labelLeft+"px";
					}
					else	{
						labelLeft = "-"+labelLeft+"px";
					}
				
					//alert(labelWidth);
					//alert(labelLeft);
				
					
					
				}
				
				$(this).prev("div.label").css("left",labelLeft);
				// show the label - cant use fade as visibility
				$(this).prev("div.label").css("visibility","visible");
			*/
				
			
			});
			
			$(".sf-menu li").mouseleave(function()	{
			
				if (menuActive)	{
					//$(this).children("div.label").css("visibility","hidden");
					
					$(this).children(".a").children(".hov").animate({bottom: "-10px"},200,"swing");
				}
				$(this).children(".hov").animate({bottom: "-10px"},300,"swing");
				
			})
			
			$("ul.sf-menu").mouseleave(function()	{
				// 
				sunTimer = setTimeout(resetSuns,1000);
				menuActive = false;
			});
			
			function resetSuns()	{
				$("sul.sf-menu a").stop(clearQueue=true);
				//$("ul.sf-menu li div.label:visible").css("visibility","hidden");
				//$("ul.sf-menu li.active a").animate({bottom: "20px"},200,"swing");
			}
			
		}
}
