
var open = null;
var pLoad = {
onData:function(data) {
	var win = Window;
	var win_width = win.width;
	var vtop = win.vscroll;
 	var el = document.createElement("div");
		el.className = "photoEnlarge";
		el.style.position = 'absolute';
		el.style.top = win.vscroll + 'px';
		el.style.left = '50px';
		el.style.zIndex = '90000';
	document.body.appendChild(el); 
	open = el;
	el.innerHTML = "<a href='javascript:closeEnlarge(this)'>[x] Close</a>" + data; 
  }  
}

function enlargePhoto(e){ 
    var ei = new EventInfo(e, true);
	var photo = ei.source;
 	var src = photo.getAttribute("src"); 
	var file = src.substring(src.indexOf("/library/") + 9, src.length); 
	if( file.indexOf("small_") == 0 ||
	    file.indexOf("medium_") == 0 ||
		file.indexOf("large_") == 0  ||
		file.indexOf("square") == 0){
		file = file.substring(file.indexOf("_") + 1, file.length);
	}
	var req = new Request(pLoad);
	    req.send("/image.php?fn=" + file);
}

function resize(img){ 
	var win = Window;
	var center = new Element(img.parentNode);   
	var y = win.vscroll + ((win.height - center.getRealHeight())/2);
	if (y < 0){ y = 0; }
	center.setPosition( (win.width - center.getRealWidth())/2, y);
}

function closeEnlarge(link){  
	open.style.display='none';
}

var mowUp = null;
var mowH = 550;
var mowLoad = {  
	onData:function(data){ 
	  
		var win = Window; //(window);
		 var el = document.createElement("div");
			el.className = "mowWin";
			el.style.position = 'absolute';
			el.style.top = 0; //Window.height/2 - ; //win.vscroll + ((win.height-550)/2);
			el.style.left = 0; //win.width + ((win.width-320)/2); 
			el.style.width = '320px';
			el.style.height = mowH + 'px';
			el.style.zIndex = '90000';
		document.body.appendChild(el); 
		mowUp = el;  
		el.innerHTML = "<a class='close' href=\"javascript:void(mowUp.style.display='none')\";>[x] Close</a>" + data;
		var win = Window;
		var center = new Element(el); 
		center.setPosition(((win.width - center.getRealWidth())/2)-100, win.scrolledy + ((win.height - center.getRealHeight())/2));
	} 
}

function openMow(nohead){  
	if(!nohead){ nohead = 0; mowH = 550; }
	else { mowH = 450; }
	var req = new Request(mowLoad);
   
	   	req.send('/mow.php?nohead=' + nohead);
}   

function openSuperfan(){
	 var win = Window; //Window;
		 var el = document.createElement("div");
			el.className = "mowWin";
			el.style.position = 'absolute';
			el.style.top = 0; //win.vscroll + ((win.height-550)/2);
			el.style.left = 0; //win.width + ((win.width-320)/2); 
			el.style.width = '320px';
			el.style.height = '240px';
			el.style.zIndex = '90000';
		document.body.appendChild(el); 
		mowUp = el;  
		el.innerHTML = "<a class='close' href=\"javascript:void(mowUp.style.display='none')\";>[x] Close</a><p>Do you have what it takes to be a Meathead Super Fan?  Do you want fame, fortune, and radical pictures of yourself posted on our homepage?  Send us your story, comments, pictures or home video and tell us how sweet you are or just how wonderful Meathead Films is.  Only the most enthusiastic and creative entries will go on to become Super Fans.  Email us today! <br /><br /><a href='mailto:superfan@meatheadfilms.com'>Superfan@meatheadfilms.com</a></p>";
		var win = Window;
		var center = new Element(el); 
		center.setPosition(((win.width - center.getRealWidth())/2)+100, win.vscroll + ((win.height - center.getRealHeight())/2));
}
  
var mailmsg = null;
function overMail(){           
    mailmsg.element.setOpacity(0.01);  
	mailmsg.element.show('block'); 
    mailmsg.effect({alpha:99.9,duration:0.2});
} 

function offMail(){           
   mailmsg.effect({alpha:0.01});
}

function moreSuperfan(){
	document.getElementById('ssco').style.overflow='visible';
	if(navigator.appName.indexOf("xplorer") == -1){
		document.getElementById('ssco').style.height='auto';  
	}
}

var markers = [];
window.onload = function(){
	
	var menu = new FlyMenu("menu");	
	
	if(navigator.appName.indexOf("xplorer") > 0){
		document.getElementById("logo").className = 'logo_ie';
		document.getElementById("banner").className = 'bannerphoto_ie';
		//document.getElementById("footer").className = 'footer_ie'; 
		document.getElementById("spacing").style.height= '57px';
		if(document.getElementById("cartpop")){
			document.getElementById("cartpop").style.top = '210px';
		}
		if(document.getElementById("storeNews")){
			document.getElementById("storeNews").style.width = '463px';
			document.getElementById("cart").style.margin = '5px 5px 0 0';
		}
		document.getElementById("emaildesc").style.top = '210px';
		if(document.getElementById("3dtext")){
			var src = document.getElementById("3dtext").getAttribute("src");
	 	    document.getElementById("3dtext").setAttribute("src","http://sites.legitify.com/meatheadfilms.com/images/blank.gif");
			document.getElementById("3dtext").setAttribute("width","378");
			document.getElementById("3dtext").setAttribute("height","150");
			document.getElementById("3dtext").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')"; 
    	}
	 	menu.list.setPosition(110, 7);
	}else{
	  document.getElementById("spacing").style.height= '0';    
	} 
	
	
	 if(document.getElementById('signup')){
	 	mailmsg = new Animation('emaildesc',{alpha:0.01});
	 	signup = new Element('signup',{onrollover:overMail,onrollout:offMail}); 
	 } 
	
	 if(markers){
		for(var m=0; m < markers.length; m++){
			map.addOverlay(markers[m]);
		}
	 }
	 Photos.make();
} 


var Photos = {
	body:null,
	matte:null,
	img:null,
	make:function(){
		//alert("load ")
		var imgs = document.getElementById("wrap").getElementsByTagName("img");
		for(var i = 0; i < imgs.length; i++){
			var src = imgs[i].getAttribute("src");
			if(imgs[i].className.indexOf("photo") >= 0 && src.match(/square_|small_|medium_/)){
				imgs[i].style.cursor = "pointer";
				imgs[i].onclick = Photos.enlarge;
			}
		}
	},
	toload:null,
	enlarge:function(e){
		
		var ei = new EventInfo(e, true);
	
		var photo = ei.source;
		var src = photo.getAttribute("src"); 
		var file = src.substring(src.indexOf("/library/") + 9, src.length); 
		if( file.indexOf("small_") == 0 ||
			file.indexOf("medium_") == 0 ||
			file.indexOf("large_") == 0  ||
			file.indexOf("square") == 0){
			file = file.substring(file.indexOf("_") + 1, file.length);
		}
	
		Photos.toload = ei.source.getAttribute("src");;
		src = src.replace(/small_|medium_|square_/,'');
		
		Photos.body = new Element(document.body);
		
		Window.construct();
		if(Photos.matte) Photos.matte.element.setContent("");
		var matte = Photos.body.append("div", "<span>LOADING</span>", 'class="photomatte" style="width:100%;height:100%;" onclick="Photos.delarge();"');
			matte.style.height = Window.height + 'px';
			matte.style.top = Window.scrolledy + 'px';
			
		Photos.matte = new Animation(matte, {alpha:0.01});
		Photos.matte.element.show('block');
		Photos.matte.effect({alpha:90, duration:0.2, fps:1/90, trans:physics.easeOut});
			
		
	    req.send("/image.php?fn=" + file);
	
	
	},
	caption:null,
	onData:function(data){
		src = Photos.toload;
		src = src.replace(/small_|medium_|square_/,'large_');
		var img = Photos.body.append("img", false, 'src="'+src+'" style="visiblity:hidden;position:absolute;top:0;left:0;z-index:6002;" onclick="Photos.delarge();"' );
			img.onload = Photos.onload;
		
		Photos.caption = Photos.matte.element.append("p", data, 'class="caption" onclick="Photos.delarge();"' );	
		
		Photos.caption.style.display = 'none';
		Photos.img = new Animation(img,{alpha:0.01});	
		
	},
	onload:function(e){
		Window.construct();
		var ei = new EventInfo(e, true);
		
		var left = (Window.width/2) - Photos.img.element.getRealWidth()/2;
		var top = (Window.height/2) + Window.scrolledy - (Photos.img.element.getRealHeight()/2);
		
		Photos.img.element.element.style.top = top + 'px';
		Photos.img.element.element.style.left = left + 'px';
				
		
		
		Photos.caption.style.display = 'block';
		Photos.caption.style.width = Photos.img.element.getRealWidth() + 'px';
		Photos.caption.style.top = ((Window.height/2) + (Photos.img.element.getRealHeight()/2) + 5) + 'px';		
		Photos.caption.style.left = left + 'px';
		//alert(Photos.caption.style.top);
		
		Photos.img.element.show();
		Photos.img.effect({alpha:99.9, duration:0.2, fps:1/90, trans:physics.easeOut});
		
		
		//Photos.caption.style.width = Photos.img.element.getRealWidth();		
		//Photos.caption.style.top = top + Photos.img.element.getRealHeight() + 'px';
		//Photos.caption.style.left = (left + Photos.img.element.getRealWidth() + 20) + 'px';
		//alert(Photos.caption.style.left);
		
		
	},
	delarge:function(){
		Photos.img.effect({alpha:0.01});
		Photos.matte.effect({alpha:0.01}, function(){ 
			Photos.body.element.removeChild(Photos.img.element.element);
			Photos.body.element.removeChild(Photos.matte.element.element);
		});
		
	},
	track:function(){
		//alert('scroll');	
		if(Photos.img){
				Window.construct();
			
				var left = (Window.width/2) - Photos.img.element.getRealWidth()/2;
				var top = (Window.height/2) + Window.scrolledy - (Photos.img.element.getRealHeight()/2);
				Photos.matte.element.element.style.top = Window.scrolledy + 'px';
					
				Photos.img.element.element.style.top = top + 'px';
				Photos.img.element.element.style.left = left + 'px';
			
		}
	}
	
}
var req = new Request(Photos);
addWindowEventListener("scroll",Photos.track);

 

