/* Grand Unified Script for FoodTee Market */

function mOver(id, new_image) {
	document.getElementById(id).src = new_image;
}


var offsetfrommouse=[20,20] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var currentimageheight = 300;	// maximum image size.
var first = 0;

function gettrailobj(){
	if (document.getElementById)
	{
		//return document.getElementById("trailimageid").style
		return document.getElementById("details_main_img").style
	}
	else if (document.all)
	{
		//return document.all.trailimageid.style
		return document.all.details_main_img.style
	}
}

function gettrailobj2(){
	if (document.getElementById)
	{
		return document.getElementById("trailimageid").style
	}
	else if (document.all)
	{
		return document.all.trailimageid.style
		//return document.all.details_main_img.style
	}
}

function truebody(){
	if (
	document.compatMode
	&& document.compatMode!="BackCompat"
	&& (!window.opera)
	)
	{
		return document.documentElement;
	}
	else
	{
		return document.body;
	}
}

function gettrailobj(){
	if (document.getElementById)
	{
		//return document.getElementById("trailimageid").style
		return document.getElementById("details_main_img").style
	}
	else if (document.all)
	{
		//return document.all.trailimagid.style
		return document.all.details_main_img.style
	}
}

function gettrailobj2(){
	if (document.getElementById)
	{
		return document.getElementById("trailimageid").style
	}
	else if (document.all)
	{
		return document.all.trailimagid.style
	}
}

function gettrailobjnostyle(){
	if (document.getElementById)
	{
		//return document.getElementById("trailimageid")
		return document.getElementById("details_main_img")
	}
	else if (document.all)
	{
		//return document.all.trailimagid
		return document.all.details_main_img
	}
}

function gettrailobjnostyle2(){
	if (document.getElementById)
	{
		return document.getElementById("trailimageid")
	}
	else if (document.all)
	{
		return document.all.trailimagid
	}
}

function followmouse(e){

	var xcoord= offsetfrommouse[0]
	var ycoord= offsetfrommouse[1]

	if (document.all)
	{
		var docwidth = truebody().scrollLeft + truebody().clientWidth;
		var docheight = Math.max(truebody().scrollHeight, truebody().clientHeight);
	}
	else
	{
		var docwidth = pageXOffset + window.innerWidth - 15;
		var docheight = Math.max(document.body.offsetHeight, window.innerHeight)
	}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 200){
			xcoord = e.pageX - xcoord - 200; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
	}

	else if (typeof window.event !="undefined"){
		if (docwidth - event.clientX < 200){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 200; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	
	//if (ycoord > (docheight / 2 + 30)) {
		ycoord -= 300;
		
	//}

	if (xcoord > (docwidth / 2) + 20) {
		xcoord -= 265;
	}

	gettrailobj2().left=xcoord+"px";
	gettrailobj2().top=ycoord+"px";	
		
}

function showtrail(imagename, caption, height){

	if (height > 0){
		currentimageheight = height;
	}

	//document.onmousemove=followmouse;

	newHTML = '<img src="' + imagename + '" border="0" /><div style="color: #999">'+caption+'</div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobjnostyle().style.visibility="visible";

}

function nullFunction() {
	Effect.Appear('trail_img', {duration: 0.5, to: 1});
}

function showtrail2(imagename, height){


	//gettrailobjnostyle2().style.visibility="hidden";
	//document.onmousemove="";

	document.onmousemove=followmouse;

	if (height > 0){
		currentimageheight = height;
	}

	if (first == 0) {
		document.onmouseout=followmouse;
	} else {
		first = 1;		
		//document.onmousemove=followmouse;
	}

	newHTML = '<div id="trail_img" class="trail_img" style="display:none;"><img src="' + imagename + '" border="0"></div>';

	gettrailobjnostyle2().innerHTML = newHTML;
	
	setTimeout("nullFunction()",250);
	
	gettrailobjnostyle2().style.visibility="visible";
	
}

function hidetrail(){
	//gettrailobj().display="none";
	gettrailobj().visibility="hidden";
	document.onmousemove="";
}


function hidetrail2(){
	//gettrailobj().display="none";
	gettrailobj2().visibility="hidden";
	document.onmousemove="";
}

function popUp(url) {
	newwindow=window.open(url,'name','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=420,left = 390,top = 362');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popUpPhoto(url) {
	newwindow=window.open(url,'name','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=490,left = 390,top = 362');
	if (window.focus) {newwindow.focus()}
	return false;
}

function signUp(email) {
	day = new Date();
	id = day.getTime();
	url = 'http://visitor.constantcontact.com/optin.jsp?m=1101327076123&oi=p&ea='+email, '" + id + "';
	newwindow=window.open(url,'name','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=640,height=480,left = 320,top = 272');	
	if (window.focus) {newwindow.focus()}
	return false;
	//eval("page" + id + " = window.open('http://visitor.constantcontact.com/optin.jsp?m=1101327076123&oi=p&ea='+email, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=640,height=480,left = 320,top = 272');");	
}

function favFiveSelect(id) {

	num_selected = 0;
	
	d = document.forms[0];
	
	for (i = 0; i < d.elements.length; i++) {
		if (d.elements[i].type == "checkbox") {
			if (d.elements[i].checked == true) {
				num_selected = num_selected + 1;
			}
		}
	}
	
	if (num_selected <= 5) {	
		if (document.getElementById(id).checked=='') {
			document.getElementById("item|"+id).setAttribute("class", "vote-item");
			document.getElementById("item|"+id).setAttribute("className", "vote-item");
			

			for (i = 0; i < d.elements.length; i++) {
				if (d.elements[i].type == "checkbox") {
					d.elements[i].disabled = false;
				}
			}
			 	
		} else {		
			document.getElementById("item|"+id).setAttribute("class", "vote-item-selected");
			document.getElementById("item|"+id).setAttribute("className", "vote-item-selected"); 	
		}
		
		if (num_selected == 5) {
			
			for (i = 0; i < d.elements.length; i++) {
				if (d.elements[i].type == "checkbox") {
					if (d.elements[i].checked == false) {
						d.elements[i].disabled = true;
					}
				}
			}			
		}
	} else {
		document.getElementById(id).checked = false;		
	}
	
	return;
}

function browseImage(div, pid, imagename, url) {
	$(div).innerHTML = 'Loading...';
	pb = 'pid='+escape(pid)+'&img='+escape(imagename)+'&base='+escape(url);
	new Ajax.Updater(div,url+'/browse_images.php', {asynchronous:true, method: 'post', postBody: pb});
}