/**/
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

/*
*	Only start the code once the DOM is ready...
*/
Event.observe(window, 'load', function(evnt)
{
		//alert('window-loaded');
});

document.observe("dom:loaded", function() {
	startList()
    //jQuery.noConflict();
	//alert('DOM-loaded');
});


getRandomItem = function(){

	// update the image
	new Ajax.Updater('ajax-container', "/portfolio/getRadomItem" , {
	    method: 'get',
	    evalScripts: true ,
	    onCreate: function(){
	
	    },
	    onComplete: function(){
            checkIfSwf();            
            new Effect.Appear('item-image',{ duration: 3.0 });

        }
	}
	);
};

getPortfolioItem = function( id , caption ){

	// update the image
	new Ajax.Updater('content', "/portfolio/fetchItem/"+id , {
	    method: 'get',
	    evalScripts: true ,
	    onCreate: function(){
        },
	onComplete: function(){

		updateCaption(caption);
        checkIfSwf();            

		new Effect.Appear('item-image',{ duration: 3.0 });

	}
	}
	);

};

checkIfSwf = function(){
    var content_type = $('item-image').readAttribute('class');    
    
    if(content_type == 'swf'){
        //swfobject.switchOffAutoHideShow();
        swfobject.embedSWF( $('swf-location').readAttribute('rel') , "myContent", "648", "465", "9", "js/swfobject/expressInstall.swf");
    }    
};

updateCopyright = function ( bool ){
	
	if( 1 == bool)	{
		new Effect.Appear('d-copyright',{ duration: 0.0 });
	} else {
		Effect.Fade('d-copyright' , { duration: 3.0 });
	}
}
updateMenu = function ( menu_id ){


				// remove current highlight...
				var children = $A($("menu").getElementsByTagName('LI'));

				children.each(function(child) {
					if(child.className == "selected"){
						child.removeClassName("selected");
					}
				});

				// highlight approiate element
				var elt = $("menu-"+menu_id);
				elt.addClassName("selected");
}

updateCaption = function ( text ){
//alert(text);
	var box = $('caption');
	box.update(text);
}

setPrev = function ( id ){
	getPortfolioItem(id);
	//$('content', 'navigation', 'footer').invoke('hide');
}

setNext = function ( type , id , name ){
	//alert(type);alert(id);alert(name);
	var next = $('next');
	next.setAttribute('onclick', "getPortfolioItem("+type+" , "+id+"); return false;"); 
	next.setAttribute('href', "#"+name ); 
}
