$(document).ready(function(){
	if(document.getElementById('masthead') != null)
		initflash();
	else
		initpage();
});

function initpage(){

// FISHBONE MAP
$("a.tip").cluetip({cluetipClass:"jtip", splitTitle:'|',tracking:true});
$("area.fishbone").cluetip({cluetipClass:"jtip", splitTitle:"|", tracking:true, showTitle:true});
$("area.labellogic").cluetip({cluetipClass:"jtip", splitTitle:"|", tracking:true, showTitle:true});
//$("area#test").cluetip({showTitle:false, tracking:true});


// MENU SECTION
$(" #nav li a img ").hover(function() {
	var nav_id = $(this).attr("id");
	$(this).attr("src",currentPath+"images/topnav/"+nav_id+"-hover.gif");
		}, function() {
	var nav_id = $(this).attr("id");
	$(this).attr("src",currentPath+"images/topnav/"+nav_id+".gif");
});
	
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
		$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});


if(document.getElementById('labellogicmap') != null){
	$('#labellogicmap').maphilight();
}
if(document.getElementById('qualitymap') != null){
	$('#qualitymap').maphilight();
}

if(document.getElementById('sitetree') != null){
	$("#sitetree").treeview({
		collapsed: true,
		animated: "medium",
		control:"#sitetreecontrol",
		persist: "location"
	});
}

$('#slidebox1wrap').serialScroll({
	target:'#slidebox1',
	items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
	prev:'area#fpnavb1',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
	next:'area#fpnavn1',// Selector to the 'next' button (absolute too)
	axis:'xy',// The default is 'y' scroll on both ways
	cycle:true,
	//interval:1000,
	duration:600// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
	//force:true
});

$('#slidebox2wrap').serialScroll({
	target:'#slidebox2',
	items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
	prev:'area#fpnavb2',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
	next:'area#fpnavn2',// Selector to the 'next' button (absolute too)
	axis:'xy',// The default is 'y' scroll on both ways
	cycle:true,
	//interval:1000,
	duration:600// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
	//force:true
});

$("area#fpnavn1").click(function() {
    var durr = 300;
	box1btm++;
	clickcount++;
	if(clickcount >= 11){
		durr = 3300;
		clickcount = 0;
	}
	if(box1btm >= 12){
		box1btm = 1;
	}
	$("img#boxbtmbkg").fadeTo(durr,0,function() {
								  $("img#boxbtmbkg").attr("src","images/slidebox1/box1_btm"+box1btm+".jpg");
								  }).fadeTo(durr,1);
});

$("area#fpnavb1").click(function() {
    var durr = 300;
	box1btm--;
	clickcount--;
	if(clickcount < 0){
		durr = 3300;
		clickcount = 11;
	}
	if(box1btm <= 0){
		box1btm = 11;
	}
   $("img#boxbtmbkg").fadeTo(durr,0,function() {
								  $("img#boxbtmbkg").attr("src","images/slidebox1/box1_btm"+box1btm+".jpg");
								  }).fadeTo(durr,1);
});

$("area#fpnavn2").click(function() {
    var durr = 300;
	box2btm++;
	clickcount++;
	if(clickcount >= 11){
		durr = 3300;
		clickcount = 0;
	}
	if(box2btm >= 12){
		box2btm = 1;
	}
	$("img#boxbtmbkg").fadeTo(durr,0,function() {
								  $("img#boxbtmbkg").attr("src",currentPath+"images/slidebox2/box2_btm"+box2btm+".jpg");
								  }).fadeTo(durr,1);
});

$("area#fpnavb2").click(function() {
    var durr = 300;
	box2btm--;
	clickcount--;
	if(clickcount < 0){
		durr = 3300;
		clickcount = 11;
	}
	if(box2btm <= 0){
		box2btm = 11;
	}
   $("img#boxbtmbkg").fadeTo(durr,0,function() {
								  $("img#boxbtmbkg").attr("src",currentPath+"images/slidebox2/box2_btm"+box2btm+".jpg");
								  }).fadeTo(durr,1);
});

$("a.zoomloc").fancybox();

}
 
function initflash(){
	if(getcookie("movietriggered") != "yes"){
		document.cookie="movietriggered=yes";
		//document.getElementById('masthead').innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='910' height='236'><param name='movie' value='AMN_masthead.swf'><param name='quality' value='high'><param name='wmode' value='transparent'><param name='FlashVars' value='ballpos=playvid'><embed src='AMN_masthead.swf' wmode='transparent' width='910' height='236' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' FlashVars='ballpos=playvid' ></embed></object>";
	}
	else{
		document.getElementById('masthead').innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='910' height='236'><param name='movie' value='AMN_masthead.swf'><param name='quality' value='high'><param name='wmode' value='transparent'><param name='FlashVars' value='ballpos=dontplayvid'><embed src='AMN_masthead.swf' wmode='transparent' width='910' height='236' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' FlashVars='ballpos=dontplayvid' ></embed></object>";	
	}
		
	initpage();
}

function getcookie ( cookiename )
{
  var results = document.cookie.match ( '(^|;) ?' + cookiename + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}