var rootdomain="http://"+window.location.hostName;

function addmodule(url) 
{
	var page_request = false;
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	{
		page_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) // if IE
	{
		try 
		{
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}
	else
	{
		return false;
	}

	page_request.open('GET', url, false); //get page synchronously 
	page_request.send(null);
	writecontent(page_request);
}

function writecontent(page_request)
{
	if (window.location.href.indexOf("http")==-1 || page_request.status==200)
	{
		dw(page_request.responseText);
	}
}

// MENU SECTION ------------------------------------------
function add_menu_title( info )
{
	dw( "<tr>" );
	dw( "<th colspan=6 align=\"center\">" );
	dw( info );
	dw( "</th>" );
	dw( "</tr>" );
}

function add_menu_title_info( info )
{
	dw( "<tr>" );
	dw( "<td colspan=6 align=\"center\">" );
	dw( info );
	dw( "</td>" );
	dw( "</tr>" );
}

function add_menu_spacer( do_image, h )
{
	if ( !do_image )
	{
		do_image = false;
	}

	if ( !h )
	{
		var h = "20px";
	}

	if ( do_image )
	{
		add_menu_spacer();
		dw( "<tr height=" + h + "><td colspan=6 align=\"center\"><img src=\"images/scroll.png\" width=66px height=26px alt=\"\"></td></tr>" );
		add_menu_spacer();
	}
	else
	{
		dw( "<tr height=" + h + "></tr>" );
	}
}

function write_icon( icon )
{
	dw( "<td align=\"center\" width=30px height=30px>" );
	if ( icon )
	{
		dw( "<img src=\"images/heart.png\" width=24px height=24px alt=\"Healthy\" title=\"Healthy Choice\">" );
	}
	dw( "</td>" );
}

function write_item( item, desc )
{
	dw( "<td width=330px valign=\"center\">" );
	if ( item )
	{
		var info = "<b>" + item + "</b>";

		if ( desc )
		{
			info = info + " - " + desc;
		}

		dw( info );
	}
	dw( "</td>" );
}

function write_price( price )
{
	dw( "<td width=48px>" );
	if ( price )
	{
		dw( price );
	}
	dw( "</td>" );
}

function add_menu_row( icon1, item1, desc1, price1, icon2, item2, desc2, price2 )
{
	dw( "<tr>" );

	write_icon( icon1 );
	write_item( item1, desc1 );
	write_price( price1 );

	write_icon( icon2 );
	write_item( item2, desc2 );
	write_price( price2 );

	dw( "</tr>" );
}

function init_menu_page()
{
	dw( "<td>" );
	dw( "<table id=\"frame\" border=0 cellspacing=5 cellpadding=0px align=\"center\">" );
	dw( "<tr>" );
	dw( "<td>" );
	dw( "<table class=\"content\" border=0 colspan=1 cellspacing=0 cellpadding=0px align=\"center\">" );
	dw( "<tr id=\"brown_bg\">" );
	dw( "<td class=\"bottom\">" );
	dw( "<div id=\"content\" align=\"center\">" );
	dw( "<p class=\"content\">" );
	dw( "<table id=\"menu_content\" border=0 cellpadding=4px cellspacing=0>" );
}

function exit_menu_page()
{
	dw( "</table>" );
	dw( "</p>" );
	dw( "</div>" );
	dw( "</td>" );
	dw( "</tr>" );
	dw( "</table>" );
	dw( "</td>" );
	dw( "</tr>" );
	dw( "</table>" );
	dw( "</td>" );
}

function start_menu_section()
{
	dw( "<td><table id=\"menu_content\" width=800px border=0 cellpadding=0px cellspacing=0 align=\"center\"><tr>" );
}

function end_menu_section()
{
	dw( "</tr></table></td>" );
}

function start_menu_column()
{
	dw( "<td valign=top><table id=\"menu_content\" border=0 cellpadding=5px cellspacing=0 align=\"center\">" );
}

function end_menu_column()
{
	dw( "</table></td>" );
}

function add_menu_item( icon, item, desc, price )
{
	dw( "<tr>" );
	write_icon( icon );
	write_item( item, desc );
	write_price( price );
	dw( "</tr>" );
}

function add_healthy_menu_spacer( do_image, h )
{
	if ( !do_image )
	{
		do_image = false;
	}

	if ( !h )
	{
		var h = "20px";
	}

	if ( do_image )
	{
		add_menu_spacer();
		dw( "<tr height=" + h + "><td colspan=11 align=\"center\"><img src=\"images/scroll.png\" width=66px height=26px alt=\"\"></td></tr>" );
		add_menu_spacer();
	}
	else
	{
		dw( "<tr height=" + h + "></tr>" );
	}
}

function write_healthy_item( item, desc )
{
	dw( "<td width=200px valign=\"center\">" );
	if ( item )
	{
		var info = "<b>" + item + "</b>";

		if ( desc )
		{
			info = info + "<br><font size=\"-1\">" + desc + "</font>";
		}

		dw( info );
	}
	dw( "</td>" );
}

function write_healthy_column( n )
{
	dw( "<td valign=\"center\" align=\"center\">" );
	var info = "" + n + "";
	dw( info );
	dw( "</td>" );
}

function add_healthy_menu_title( info )
{
	dw( "<tr>" );
	dw( "<th colspan=11 align=\"center\">" );
	dw( info );
	dw( "</th>" );
	dw( "</tr>" );
}

function add_healthy_menu_title_info( info )
{
	dw( "<tr>" );
	dw( "<td colspan=11 align=\"left\">" );
	dw( info );
	dw( "</td>" );
	dw( "</tr>" );
}

function add_healthy_menu_row( item, desc, cal, fat, sat, chol, sodium, carbs, fiber, sugars, pro, veg )
{
	dw( "<tr>" );

	write_healthy_item( item, desc );
	write_healthy_column( cal ); // Calories
	write_healthy_column( fat ); // Fat
	write_healthy_column( sat ); // Sat F
	write_healthy_column( chol ); // Chol
	write_healthy_column( sodium ); // Sodium
	write_healthy_column( carbs ); // Carbs
	write_healthy_column( fiber ); // Fiber
	write_healthy_column( sugars ); // Sugars
	write_healthy_column( pro ); // Pro
	write_healthy_column( veg ); // Fr/Veg

	dw( "</tr>" );
}

// GLOW SECTION -------------------------------------------
function glow_on( n )
{
	img_name = n;
	if ( n.search( "2" ) >= 0 )
	{
		img_name = n.replace( "2", "" );
	}

	document.getElementById( n ).src = "images/" + img_name + "_glow.png";
}
function glow_off( n )
{
	img_name = n;
	if ( n.search( "2" ) >= 0 )
	{
		img_name = n.replace( "2", "" );
	}

	document.getElementById( n ).src = "images/" + img_name + ".png";
}

// SLIDESHOW SECTION --------------------------------------

var slideshow_index = 0;
var slideshow_images = new Array();

function init_image( img_name )
{
	var img = new Image();
	img.src = img_name;

	slideshow_images[ slideshow_images.length ] = img;
}

function do_slideshow()
{
	var delay = 4;
	delay = delay * 1000;

// 	TODO: Fix me!
//	document.images.slideshow.src = slideshow_images[ slideshow_index ].src
//	if ( !is_image_loaded( slideshow_images[ slideshow_index ].src ) )
//	{
//		setTimeout( "do_slideshow()", 0.1 );
//		return;
//	}
//
//	document.getElementById( "slideshow_preloader" ).src = null;

	blendimage( "slideshow_bg", "slideshow_id", slideshow_images[ slideshow_index ].src, 500 );
	slideshow_index++;
	setTimeout( "do_slideshow()", delay );

	if ( slideshow_index == slideshow_images.length )
	{
		slideshow_index = 0;
	}

	var hack_to_set_the_global_var_above_this_does_nothing_but_works = 1;
} 

function opacity( id, opacStart, opacEnd, millisec ) 
{
	//speed for each frame
	var speed = Math.round( millisec / 100 );
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if( opacStart > opacEnd ) 
	{
		for( i = opacStart; i >= opacEnd; i-- ) 
		{
			setTimeout( "changeOpac( " + i + ",'" + id + "' )",( timer * speed ) );
			timer++;
		}
	} 
	else if( opacStart < opacEnd ) 
	{
		for( i = opacStart; i <= opacEnd; i++ )
		{
			setTimeout( "changeOpac( " + i + ",'" + id + "' )",( timer * speed ) );
			timer++;
		}
	}
}

function is_image_loaded( imgsrc )
{
	if ( !document.getElementById( "slideshow_preloader" ).src )
	{
		document.getElementById( "slideshow_preloader" ).src = imgsrc;
	}

	if ( !document.getElementById( "slideshow_preloader" ).complete )
	{
		return false;
	}

	return true;
}

//change the opacity for different browsers
function changeOpac( opacity, id ) 
{
	var object = document.getElementById( id ).style; 
	object.opacity = ( opacity / 100 );
	object.MozOpacity = ( opacity / 100 );
	object.KhtmlOpacity = ( opacity / 100 );
	object.filter = "alpha( opacity=" + opacity + " )";
}

function shiftOpacity( id, millisec ) 
{
	//if an element is invisible, make it visible, else make it ivisible
	if( document.getElementById( id ).style.opacity == 0 ) 
	{
		opacity( id, 0, 100, millisec );
	}
	else
	{
		opacity( id, 100, 0, millisec );
	}
}

function blendimage(divid, imageid, imagefile, millisec) 
{
	var speed = Math.round( millisec / 100 );
	var timer = 0;
	
	//set the current image as background
//	document.getElementById( divid ).style.backgroundImage = "url(" + document.getElementById( imageid ).src + ")";
	document.getElementById( divid ).src = document.getElementById( imageid ).src;
	
	//make image transparent
	changeOpac( 0, imageid );
	
	//make new image
	document.getElementById( imageid ).src = imagefile;

	//fade in image
	for( i = 0; i <= 100; i++ ) 
	{
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",( timer * speed ) );
		timer++;
	}
}

// Gradient Section ---------------------------------------
function right_gradient()
{
	dw( "<td id=\"right_gradient\" width=\"75px\"><img src=\"\" width=\"75px\" height=\"0\" alt=\"\"></td>" );
}

function left_gradient()
{
	dw( "<td id=\"left_gradient\" width=\"75px\"><img src=\"\" width=\"75px\" height=\"0\" alt=\"\"></td>" );
}

// Paragraph Seperator
function paragraph_sep()
{
	dw( "<br><br><img src=\"images/scroll.png\" alt=\"\"><br><br>" );
}

// Gallery Section ----------------------------------------
var gallery_index = 0
var gallery_group_index = 0
function new_gallery_section()
{
	gallery_index = 0;
	gallery_group_index++;
	dw( "<div class=\"highslide-gallery\">" );
}

function end_gallery_section()
{
	dw( "</div>" );
}

function add_gallery_image( n, caption )
{
	if ( gallery_index == 0 )
	{
		dw( "<tr>" );
	}

	dw( "<td>" )

	var line1 = "<a href=\"gallery/" + n + ".JPG\" class=\"highslide\" onclick=\"return hs.expand(this)\">";
	var line2 = "<img src=\"gallery/thumb/" + n + ".JPG\" atl=\"" + n + "\" title=\"Click to Enlarge\" border=\"5\" width=128px /></a>";
	var line3 = "";

	if ( caption )
	{
		line3 += "<div class=\"highslide-caption\">" + caption + "</div>";
	}

	dw( line1 + line2 + line3 ); 

	dw( "</td>" );

	gallery_index++;

	if ( gallery_index == 4 )
	{
		dw( "</tr>" );
		gallery_index = 0;
	}
}

// Award Section ------------------------------------------
function add_award( img, award, stars, maxstars, info, date_info )
{
	dw( "<table id=\"menu_content\" width=800px border=0 cellpadding=4px cellspacing=0 align=\"center\">" );
	dw( "<tr>" );
	dw( "<td align=\"center\" width=390px>" );
	dw( "<img src=\"images/" + img + "\" alt=\"\">" );

	if ( award )
	{
		dw( "<H3 class=\"award\">" + award + "</H3>" );
	}

	if ( date_info )
	{
		dw( "<H3 class=\"award\">" + date_info + "</H3>" );
	}

	dw( "</td>" );
	dw( "<td align=\"center\">" );

	for( i = 0; i < maxstars; i++ )
	{
		var diff = stars - i;
		if ( diff > 0.5 )
		{
			dw( "<img src=\"images/award_star.png\" alt=\"\">" );
		}
		else if( diff <= 0 )
		{
			dw( "<img src=\"images/award_graystar.png\" alt=\"\">" );			
		}
		else
		{
			dw( "<img src=\"images/award_halfstar.png\" alt=\"\">" );
		}
	}

	dw( "<br>" );
	dw( info );
	dw( "</td>" );
	dw( "</tr>" );
	dw( "</table>" );
}

// MUSIC SECTION ------------------------------------------
function music()
{
//	var music = "music/furelise.mp3";
//	dw( "<embed src=\"" + music + "\" hidden=\"false\" border=\"0\" width=\"20\" height=\"20\" autostart=\"true\" loop=\"true\">" )
}

// VIDEO SECTION ------------------------------------------
function add_movie_fromlink( is_ie )
{
	u = document.URL;
	video = u.substring( u.indexOf('?') + 1, u.length );

	if ( is_ie )
	{
		dw( "<object type=\"application/x-shockwave-flash\" data=\"./video/" + video + "\" width=\"720\" height=\"386\">" );
	}
	else
	{
		dw( "<param name=\"movie\" value=\"./video/" + video + "\" />" );
	}

}

// Utility ------------------------------------------------
function dw( str )
{
	document.write( str );
}


// DROP DOWN LINKS ----------------------------------------
var dropmenu = function()
{
	var t = 15;
	var z = 50;
	var s = 6;
	var a;

	function dropdown( n )
	{
		this.n = n;
		this.h = [];
		this.c = [];
	}

	dropdown.prototype.init = function( p, c )
	{
		a = c;
		var w = document.getElementById( p );
		var s = w.getElementsByTagName( 'ul' );
		var l = s.length;
		var i = 0;
		for( i; i < l; i++ )
		{
			var h = s[ i ].parentNode; 
			this.h[ i ] = h;
			this.c[ i ] = s[ i ];
			h.onmouseover = new Function( this.n + '.st(' + i + ', true )' );
			h.onmouseout = new Function( this.n + '.st(' + i + ')' );
		}
	}

	dropdown.prototype.st = function( x, f )
	{
		var c = this.c[x];
		var h = this.h[x];
		var p = h.getElementsByTagName( 'a' )[ 0 ];
		// Get the img
		var img = h.getElementsByTagName( 'img' )[ 0 ];
		clearInterval( c.t );
		c.style.overflow = 'hidden';

		if( f )
		{
			//glow_on( img.id );
//			img.src = "images/" + img.id + "_glow.png";

			p.className+=' ' + a;

			if(!c.mh)
			{
				c.style.display = 'block';
				c.style.height = '';
				c.mh = c.offsetHeight;
				c.style.height = 0;
			}

			if( c.mh == c.offsetHeight)
			{
				c.style.overflow = 'visible';
			}
			else
			{ 
				c.style.zIndex = z;
				z++;
				c.t = setInterval( function(){ sl( c, 1 ) }, t );
			}
		}
		else
		{
//			img.src = "images/" + img.id + ".png";
			p.className = p.className.replace( a, '' );
			c.t=setInterval( function(){ sl( c, -1 ) }, t );
		}
	}

	function sl( c, f )
	{
		var h = c.offsetHeight;
		if( (h <= 0 && f != 1 ) || ( h >= c.mh && f == 1 ) )
		{
			if( f == 1 )
			{
				c.style.filter = '';
				c.style.opacity = 1;
				c.style.overflow = 'visible';
			}

			clearInterval( c.t ); 
			return;
		}

		var d = ( f == 1 ) ? Math.ceil( ( c.mh - h ) / s ) : Math.ceil( h / s );
		var o = h / c.mh;
		c.style.opacity = o; 
		c.style.filter = 'alpha(opacity=' + ( o * 100 ) + ')';
		c.style.height = h + ( d * f ) + 'px';
	}

	return {dropdown:dropdown}
}();