var musicopen = "";

function addLoadEvent ( func ) {
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

var music = {
	get_cookie : function (Name) {
	  var search = Name + "="
	  var returnvalue = "";
	  if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
		  offset += search.length
		  end = document.cookie.indexOf(";", offset);
		  if (end == -1)
			 end = document.cookie.length;
		  returnvalue=unescape(document.cookie.substring(offset, end))
		  }
	   }
	  return returnvalue;
	},
	preload : function () {
		el = document.getElementById("menu_music");
		links = el.getElementsByTagName("a");
		links[0].onclick = new Function ( "return music.reloadMusic();" );
		links[1].onclick = new Function ( "return music.unloadMusic();" );
		if (music.get_cookie("musicwin")==""){
			document.cookie="musicwin=yes";
			music.reloadMusic();
		}
	},
	reloadMusic : function () {
			mw=window.open("music.html","acb_music","width=150,height=150");
			mw.blur();
			window.focus();
			document.cookie="musicwin=yes";
			return true;
	},
	unloadMusic : function () {
			mw=window.open("music-off.html","acb_music","width=150,height=150");
			mw.blur();
			window.focus();
			document.cookie="musicwin=yes";
			return false;
	}
}

var florals = {
	preload : function () {
		el = document.getElementById("thumbs");
		var thmbs = el.getElementsByTagName("li");
		var thmblink = "";
		for ( i=0; i<thmbs.length; i++ ) {
			thmblink = thmbs[i].getElementsByTagName("a");
			thmblink[0].onmouseover = new Function ( "if (curImg != 'marquis_" + (i+1) + "') {new Effect.Fade(curImg,{duration: 0.4, queue: 'parallel'});new Effect.Appear('marquis_" + (i+1) + "',{duration: 0.4, queue: 'parallel'});curImg = 'marquis_" + (i+1) + "';}");
			thmblink[0].onclick = new Function ( "return false;" );
		}
		el = document.getElementById("marquis");
		thmbs = el.getElementsByTagName("a");
		for ( i=0; i<thmbs.length; i++ ) {
			thmbs[i].onclick = new Function ( "return false;" );
		}
	}
}

var portfolio = {
	preload : function () {
		el = document.getElementById("thumbs");
		var thmbs = el.getElementsByTagName("li");
		for ( i=0; i<thmbs.length; i++ ) {
			thmbs[i].onmouseover = new Function ( "if (curImg != 'marquis_" + (i+1) + "') {new Effect.Fade(curImg,{duration: 0.4, queue: 'parallel'});new Effect.Appear('marquis_" + (i+1) + "',{duration: 0.4, queue: 'parallel'});curImg = 'marquis_" + (i+1) + "';}");
		}
	},
	eventPreload : function () {
		el = document.getElementById("thumbs");
		var thmbs = el.getElementsByTagName("li");
		for ( i=0; i<thmbs.length; i++ ) {
			thmbs[i].onmouseover = new Function ( "if (curImg != 'marquis_" + (i+1) + "') {new Effect.Fade(curImg,{duration: 0.4, queue: 'parallel'});new Effect.Appear('marquis_" + (i+1) + "',{duration: 0.4, queue: 'parallel'});curImg = 'marquis_" + (i+1) + "';}");
			thmbs[i].onclick = new Function ( "return false;" );
		}
	}
}


var contact = {
	preload : function () {
		var fm = document.getElementsByTagName("form");
		if ( fm.length > 0 ) {
			fm[0].onsubmit = new Function ( "return contact.checkForm(this);" );
		}
	},
	checkForm : function (fm) {
		var ins = fm.getElementsByTagName("input");
		var elist = "";
		var lastLb = "";
		radsChecked = "Please tell us how you heard about us.\n";
		for ( i=0; i<ins.length; i++ ) {
			if ( ins[i].className.indexOf("required") != -1 ) {
				if ( ins[i].value == "" ) {
					pn = ins[i].parentNode;
					lb = pn.getElementsByTagName("label");
					if ( lb.length > 0 ) {
						tx = lb[0].firstChild;
						if ( tx.nodeValue != lastLb ) {
							elist += tx.nodeValue + "\n";
						}
						lastLb = tx.nodeValue;
					}
				} else {
					if ( ins[i].getAttribute("type") == "radio" ) {
						if ( ins[i].checked ) {
							radsChecked = "";
						}
					}
				}
			}
		}
		elist += radsChecked;
		if ( elist != "" ) {
			alert( "Please be sure the following information is complete:\n\n" + elist );
			return false;
		}
		return true;
	}
}


var about = {
	preload : function () {
		el = document.getElementById("content");
		var blocks = el.getElementsByTagName("li");
		
		for ( i=0; i<blocks.length; i++ ) {
			//get "a" tag children of each list item			
			// The first "a" tag will always be the image.
			var imgTag = blocks[i].getElementsByTagName("a");
						
			//and onclick we run "l" to open a new window wih the href of the image tag
			imgTag[0].onclick = new Function ( "about.l ( 'larger.php?img=' + this.href ); return false;" );
		}
	},
	l : function ( iid ) {
		// iid is the full URL, including the image URl in a http://currentsite/larger.php?img=IMGURL
		window.open( iid, "larger", "width=400,height=400,resizable=yes,scrollbars=yes" );
		return false;
	}
}

var pl = {
	checkBody : function ( ) {
		bd = document.body;
		if ( bd.id == "portfolio" ) {
			portfolio.preload();
		}
		if ( bd.id == "florals" ) {
			florals.preload();
		}
		if ( bd.id == "event" ) {
			portfolio.eventPreload();
		}
		if ( bd.id == "about" ) {
			about.preload();
		}
	}
}

if ( document.getElementById && document.getElementsByTagName ) { 
	addLoadEvent(pl.checkBody);
	addLoadEvent(music.preload);
}

