// JavaScript Document


/* 
 * Mouseover star stuff  
 */
var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOvers = new Array();
var mouseOuts = new Array();
var ocl = new Array();
var select = -1;
var name2 = "";
var temp = 0;
var imgs;

window.onload = init;

function init()
{
        if (!W3CDOM) return;
        var nav = document.getElementById('stars');
        imgs = nav.getElementsByTagName('img');
        for (var i=0;i<imgs.length;i++)
        {
                imgs[i].onmouseover = mouseOver;
                imgs[i].onmouseout = mouseOut;
				imgs[i].onclick = clic;
                var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
                mouseOuts[i] = new Image();
                mouseOuts[i].src = imgs[i].src;
                mouseOvers[i] = new Image();
                mouseOvers[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_omo" + suffix;
                imgs[i].number = i;
				ocl[i] = new Image;
				ocl[i].src = mouseOvers[i].src;
        }
		
		nav.style.display = "none";

}

function clic()
{
        if (document.images)
        {
				imgs[this.number].src = ocl[this.number].src
                temp = select;
                select = this.number;
 				document.getElementById("rating").innerText = "Your rating:";
               if (temp != -1) {mouseOut();}
        }
}

function mouseOver()
{
	if (document.images && select != this.number)
	{
		var num = this.number;
		//while(num >=5) {num = num - 5;}

		var str = "I hate it";
		if( num == 1 )
			str = "I don't like it";
		else if(num == 2 )
			str = "It's ok";
		else if(num == 3)
			str = "I like it";
		else if(num == 4)
			str = "I love it!";
		
        this.src = mouseOvers[this.number].src;
		document.getElementById("rating").innerText = str;
	
	
		for(;num>=0;--num)
		{
			imgs[this.number-num].src = mouseOvers[this.number-num].src;
		}
	}
}

function mouseOut()
{
	if (document.images && select != this.number) {
        this.src = mouseOuts[this.number].src;
		document.getElementById("rating").innerText = "Rate it:";
		
		var num = this.number;
		for(;num>=0;--num)
		{
			imgs[this.number-num].src = mouseOuts[this.number-num].src;
		}

	}
}


/*
 * menuExpandable3.js - implements an expandable menu based on a HTML list
 * Adapted from Dave Lindquist (http://www.gazingus.org)
 */

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;

    actuator.parentNode.style.backgroundImage = "url(images/plus.gif)";
    actuator.onclick = function() {
        var display = menu.style.display;
        this.parentNode.style.backgroundImage =
            (display == "block") ? "url(images/plus.gif)" : "url(images/minus.gif)";
        menu.style.display = (display == "block") ? "none" : "block";

        return false;
    }
}

function clickedView(menuId, actuatorId) {
	var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;
	menu.style.display = "block";
	actuator.parentNode.style.backgroundImage = "url(images/minus.gif)";
	
}


/* checks checkbox */
 function modifyBox(box){ 
	document.getElementsByTagName('input')[box].checked=true;
 } 

/* adds to shopping list */
function addToList() {
	var stars = document.getElementById("stars");
	stars.style.display = "block";
}

/* moves to favorites */
function addToFavs() {
	var stars = document.getElementById("stars");
	stars.style.display = "none";
	
	var favs = document.getElementById("favs");
	favs.style.display = "block";
	
  clickedView("favoritesMenu", "favoritesActuator");

}


/* popup small-ish window for quizzes  */
function popColor(url)
{
        win=window.open(url,'name','height=400,width=465,resizable=yes,');
        if (window.focus) {win.focus()}
}

function popFlavor(url)
{
        win=window.open(url,'name','height=550,width=450,resizable=yes,');
        if (window.focus) {win.focus()}
}

function popList(url)
{
	    win=window.open(url,'name','height=490,width=550,resizable=yes,');
        if (window.focus) {win.focus()}
}
