var fadeTime=150;
var slowFade=300;
if(!page_prop) {
	var page_prop	= {
			'main'	: '',
			'sub'	: ''
		};
}
$(document).ready(function(){

$('a').focusin(function(){
	$(this).blur();
});

	$('#header').mouseleave(function() { 
		  $('#menu1 > div:not(#crumb)').stop(true,true).fadeOut('fast');
	} );

	$('.roll-me').hover(
		function() {
			var sub=this.src;
			if(sub.substring(sub.length-5,sub.length)!='2.png'){
				this.src = this.src.replace(".png","2.png");
			}
		  
		  var thisid = $(this).parents('div:first').attr('id');
		  if(thisid) {
			$('.sub1').hide();
			$('#menu1 > div:not(.'+thisid+',#crumb)').stop(true,true).hide();
			$('div.' + thisid).stop(true,true).fadeIn(fadeTime);
		  }
		},
		function() { this.src = this.src.replace("2.png",".png"); }
	);
	$('.showSub1').mouseenter(function(){
		show=$(this).attr('show');
		showW=$('#'+show).css('display');
		if(showW=='none'){
			$('#'+show+' div').stop(true,true).hide();
			if($.browser.mozilla){
				$('#'+show).show(500,function(){
					$('#'+show+' div').fadeIn(500);
				});
			}else if($.browser.webkit){
				$('#'+show).css({'width':'0px'}).animate({'display':'block','width':'145px'},500,function(){
					$('#'+show+' div').animate({'display':'block','opacity':'toggle'},500);
				});
			}else if($.browser.msie){
				if(parseInt($.browser.version)>8){
					$('#'+show).show(500,function(){
						$('#'+show+' div').fadeIn(500);
					});
				}else if(parseInt($.browser.version)>7){
					//IE8
					$('#'+show).show(40,function(){
						$('#'+show+' div').fadeIn(300);
					});				
				}else{
				//7
					$('#'+show).show(500,function(){
						$('#'+show+' div').fadeIn(500);
					});				
				}
			}
		}



	/*
		show=$(this).attr('show');
		otherW=$('.sub1:not(#'+show+')').width();
		if(otherW){
			$('.sub1:not(#'+show+') div').stop(true,true).hide();
			//$('.sub1:not(#'+show+')').stop(true,true).animate({'display':'none','width':'0px'},350,'swing',function(){$(this).hide();});
			$('.sub1:not(#'+show+')').stop(true,true).hide(400);
		}
		//$('#'+show).stop(true,true).fadeIn(slowFade);
		$('#'+show+' div').stop(true,true).hide();
		$('#'+show).css({'width':'0px'}).stop(true,true).animate({'display':'block','width':'145px'},500,'swing',function(){
			$('#'+show+' div').stop(true,true).animate({'display':'block','opacity':'toggle'},600);
		});
	*/
	});
	//highligh links for active page
	if(page_prop.main != "") {
		mainOn(page_prop.main);
		$("#menu1 ." + page_prop.main).stop(true,true).show();
		if(page_prop.sub != '') {
			lvl1On(page_prop.sub);
		}
	}
	
	//highlight for level2	
	$('.sub1 img').hover(function(){
		var sub=this.src;
		if(sub.substring(sub.length-5,sub.length)!='2.png'){
			this.src = this.src.replace(".png","2.png");
		}		
	},function(){
		this.src = this.src.replace("2.png",".png");
	});
	
//show fullsize from thumbnail clicked
var current;
   $('#print .thumb').click(function (){
		current = $(this);
		showBig(current);
   });

//hide fullsize image after clicking on anything that isn't the image 
   $('html:not(#container)').click(function (){
		hideBig();
   });
//show next when clicking on the current image go back to start when finished
	var theList = $('li').first();
	$('#container').click(function (){
		next = current.next();
		if(next.length){
			hideBig(true);
			current=next;
			showBig(current);
		}else{
			//alert('no next thumb');
			hideBig(true);
			theList = theList.next();
			//alert(theList.length);
			if(theList.length){
				//alert('next list');
				current=theList.children();
			}else{
				//alert('no more lists');
				theList = $('li').first();
				current=theList.children();
				//alert('back to start of list and thumbs');
			}
			showBig(current);		
		}
	});
   

	//highlight the thumbnails
	$('.thumb img').hover(function(){
		$(this).stop(true,true).animate({"opacity":"1.0","filter":"alpha(opacity=100)"},200);
	},function(){
		$(this).stop(true,true).animate({"opacity":".8","filter":"alpha(opacity=80)"},200);
	});


});

function showBig(current){

		$('#fullSize').hide();
		var big=$(current).attr('full');
		var swfCount=0;
		var	bigs=big.split('@');

		var title=$(current).attr('fileTitle');
		var description=$(current).attr('fileDescription');
		if(title==undefined){
		$('#container').html('<div><img src="img/'+big+'" /></div>')
		.fadeIn(fadeTime);		
		}else{

					theHtml ='';
					for(x=0;bigs.length>x;x++){
						ext=bigs[x].substr(-3);
						if($.browser.msie){
							ext=bigs[x].substring(bigs[x].length-3,bigs[x].length);
						}					
						if(ext=='swf'){
							swfCount++;
							theHtml+='<div class="theFulls" style="margin-left:48px;"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="550" HEIGHT="400" id="myMovieName"><PARAM NAME=movie VALUE="'+bigs[x]+'"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="'+bigs[x]+'" quality=high bgcolor=#FFFFFF WIDTH="550" HEIGHT="400" NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT></div>';
						}else{
							theHtml+='<div class="theFulls"><img src="'+bigs[x]+'" /></div>';
						}
					
					}
					theHtml+='<div class="clear"></div><div id="title">'+title+'</div><div class="clear"></div><div id="description">'+description+'</div><div class="clear"></div>';
			$('#container').html(theHtml);
			$('#loading').fadeIn(fadeTime);
			
			if(bigs.length==1){		
				$('#fullSize img').last().load(function(){
					$('#fullSize').stop(true,true).css({'display':'block'});
					var width = $(this).width();
					$('#container').width(width);
					$('#loading,#nextBtn,#prevBtn').stop(true,true).fadeOut(fadeTime);				
					//var fullSizeWidth = $('#fullSize').width();
					var titleW=$('#title').width();
					var descW=$('#description').width();
					$('#title').css('margin-left',(width-titleW)/2+'px');
					$('#description').css('margin-left',(width-descW)/2+'px');
					$('#fullSize').css('margin-left',(645-width)/2+'px');
					//$('#fullSize').stop(true,true).fadeIn(slowFade);
					$('#fullSize').css({'width':'0px','visibility':'visible'}).stop(true,true).animate({"width":width},700,'easeOutCubic');					
				});			
			}else{				
				var xx=0;
				var width=645;				
				$('#fullSize img').load(function(){
					xx++;
								
					if(xx==1){
							
						//first load
						$('#container').width(645);
						$('#fullSize').css('margin-left','0px');
						$('#fullSize').stop(true,true).css({'display':'block','visibility':'hidden'});
						thisWidth=$(this).width();
						$(this).css('margin-left',(645-thisWidth)/2+'px');
						
					}
					if((xx+swfCount)==bigs.length){
						//last load
						$('#loading,#nextBtn,#prevBtn').stop(true,true).fadeOut(fadeTime);
						var titleW=$('#title').width();
						var descW=$('#description').width();
						$('#title').css('margin-left',(width-titleW)/2+'px');
						$('#description').css('margin-left',(width-descW)/2+'px');						
						thisWidth=$(this).width();
						$(this).css('margin-left',(645-thisWidth)/2+'px');
						
						$('#fullSize').css({'width':'0px','visibility':'visible'}).stop(true,true).animate({"width":width},700,'easeOutCubic');
					}else{
						//in between
						thisWidth=$(this).width();
						$(this).css('margin-left',(645-thisWidth)/2+'px');
					}				
				});		

				


			}



		}

}

function hideBig(hide){
	if(hide){
		$('#fullSize').stop(true,true).hide();
	}else{
		$('#fullSize').stop(true,true).fadeOut(slowFade);
	}
	var tmb = $('.thumb').size();
	if(tmb<12){
		//$('#footer').stop(true,true).fadeIn(fadeTime);
	}else{
		$('#nextBtn,#prevBtn').stop(true,true).fadeIn(fadeTime);
	}
	
	
}


function level1Menu(){
	return false;
	var linkId;
   $('#links div').hover(function(){//show menu and hight light main link
		linkId=$(this).attr('id');
		mainOn(linkId);
		
		if(linkId != page_prop.main && page_prop.main != '') { $('#menu1 .' + page_prop.main).stop(true,true).fadeOut(fadeTime); }
		
		// $('#menu1 .'+linkId).stop(true,true).fadeIn(fadeTime);
		$('#menu1 .'+linkId).fadeIn(fadeTime);
		
   },function(){//un highlight the main link and fade menu
		if(page_prop.main == '' || page_prop.main != linkId) { mainOff(linkId); }
		
		
		if(page_prop.main != linkId) { 
			// $('#menu1 .'+linkId).stop(true,true).fadeOut(fadeTime); 
			$('#menu1 .'+linkId).fadeOut(fadeTime); 
		} //keep the page's assigned submenu from fading if mouseout on the menu
		
		
		$('#menu1 .'+linkId).hover(function(e){//but highlight and keep menu if hovered over the menu and show dropdown
			mainOn(linkId);
			$(this).stop(true,true).show();			
			level2Menu(linkId);				
		},function(){
			$(this).stop(true,true).css("display","inline").fadeOut(fadeTime);
			
			if(page_prop.main == '' || page_prop.main != linkId) { mainOff(linkId); }
			
		});
		
		
		if(page_prop.main == '' || page_prop.main != linkId) { $('#menu1 .' + page_prop.main).stop(true,true).fadeIn(fadeTime); }
   });
}

function level2Menu(linkId){
	return false;
	var lvl2;
	$('#menu1 .'+linkId+' div').hover(function(){
		
		if(linkId != page_prop.main && page_prop.main != '') { $('#menu1 .' + page_prop.main).stop(true,true).fadeOut(fadeTime); }
		
		lvl2=$(this).attr('class');
		lvl1On(lvl2);
		// $('#dropdown .'+lvl2).stop(true,true).css("display","none").animate({"opacity":"show","height":"toggle"},fadeTime);
		$('#dropdown .'+lvl2 + ' div').fadeIn(); 
		$('#dropdown .'+lvl2).slideDown(fadeTime); 
	},function(){
		lvl1Off(lvl2);
		// $('#dropdown .'+lvl2).stop(true,true).css("display","inline").animate({"opacity":"hide","height":"toggle"},fadeTime)
		$('#dropdown .'+lvl2).slideUp(fadeTime)
		.hover(function(){
			mainOn(linkId);
			lvl1On(lvl2);
			$('#menu1 .'+linkId).stop(true,true).show();
			$('#dropdown .'+lvl2).stop(true,true).show();				
		},function(){
			// $('#dropdown .'+lvl2).stop(true,true).css("display","inline").animate({"opacity":"hide","height":"toggle"},fadeTime);
			$('#dropdown .'+lvl2).slideUp(fadeTime);
			
			if(page_prop.main != linkId) { 
				// $('#menu1 .'+linkId).stop(true,true).css("display","inline").fadeOut(fadeTime); 
				$('#menu1 .'+linkId).fadeOut(fadeTime); 
			} //prevent the page's submenu from being hidden
			
			if(page_prop.sub != lvl2) { lvl1Off(lvl2); } //try to prevent the sublevel highlighting for the current page item
			
			if(page_prop.main == '' || page_prop.main != linkId) { mainOff(linkId); }
		});
	});
}
//high lights works company ad rants
function mainOn(linkId){
	$('#links #'+linkId+' img').attr('src','img/'+linkId+'2.png');
}
//return works company ad rants to normal
function mainOff(linkId){
	$('#links #'+linkId+' img').attr('src','img/'+linkId+'.png');
}
function lvl1On(lvl2){
	$('#menu1 .'+lvl2+' img').attr('src','img/'+lvl2+'2.png');
}
function lvl1Off(lvl2){
	$('#menu1 .'+lvl2+' img').attr('src','img/'+lvl2+'.png');
}
function lvl2On(drop){
	$('#dropdown #'+drop+' img').attr('src','img/'+drop+'2.png');
}
function lvl2Off(drop){
	$('#dropdown #'+drop+' img').attr('src','img/'+drop+'.png');
}



