// menu hover

function lightUp(imgName) {
	if (document.images) {
		imgOn = 'images/menu_' + imgName + '_selected.gif';
		document.getElementById(imgName).style.background = 'url(' + imgOn + ')';
		document.getElementById(imgName).style.backgroundRepeat = 'no-repeat';
	}
	
	switch(imgName) {
		case 'design': case 'develop': case 'document':
			document.getElementById('bigd').style.background = 'url(images/menu_big_d_selected.gif)';
			document.getElementById('bigd').style.backgroundRepeat = 'no-repeat';
			break;
		default:
			break;
	}
}

function turnOff(imgName) {
	if (document.images) {
		imgOff = 'images/menu_' + imgName + '.gif';
		document.getElementById(imgName).style.background = 'url(' + imgOff + ')';
		document.getElementById(imgName).style.backgroundRepeat = 'no-repeat';
	}

	switch(imgName) {
		case 'design': case 'develop': case 'document':
			var bkgdUrl = document.getElementById('bigd').style.background;
			var bkgdUrlLength = bkgdUrl.toString.length * -1;
			if (bkgdUrl.substr(bkgdUrlLength, -13) == '_selected.gif') {
				document.getElementById('bigd').style.background = 'url(images/menu_big_d_selected.gif)';
			} else {
				var url = document.URL;
				var DocName =(url.substring(url.lastIndexOf("\\")+1,url.lastIndexOf("\."))) // for windows
				var DocName =(url.substring(url.lastIndexOf("\/")+1,url.lastIndexOf("\."))) // for *nix 
				switch(DocName) {
					case 'design': case 'develop': case 'document':
						document.getElementById('bigd').style.background = 'url(images/menu_big_d_current.gif)';
						break;
					default:
						document.getElementById('bigd').style.background = 'url(images/menu_big_d.gif)';
						break;
				}
			}
			document.getElementById('bigd').style.backgroundRepeat = 'no-repeat';
			break;
		default:
			break;
	}
}

// initialize menu buttons

function preloadimages() {
	var myimages = new Array();
	var selimages = new Array();
	var curimages = new Array();
	for (i=0; i<preloadimages.arguments.length; i++) {
		myimages[i] = new Image();
		myimages[i].src = '../images/menu_' + preloadimages.arguments[i] + '.gif';
	}
	for (j=0; j<preloadimages.arguments.length; j++) {
		curimages[j] = new Image();
		curimages[j].src = '../images/menu_' + preloadimages.arguments[j] + '_current.gif';
	}
	for (k=0; k<preloadimages.arguments.length; k++) {
		selimages[k] = new Image();
		selimages[k].src = '../images/menu_' + preloadimages.arguments[k] + '_selected.gif';
	}
}



function initMenu(imgName) {

    if (navigator.userAgent.toLowerCase().match('chrome') || navigator.userAgent.toLowerCase().match('safari')) {
        document.getElementById('portfolio').style.clear = 'both';
	}
		
	preloadimages("home","search","contact","print","word","design","develop","document","big_d");

	document.getElementById(imgName).style.background = 'url(images/menu_' + imgName + '_current.gif)';
	document.getElementById(imgName).style.backgroundRepeat = 'no-repeat';
	switch(imgName) {
		case 'design': case 'develop': case 'document':
			document.getElementById('bigd').style.background = 'url(images/menu_big_d_current.gif)';
			document.getElementById('bigd').style.backgroundRepeat = 'no-repeat';
			break;
		default:
			break;
	}
}

// JQuery Photo Gallery

$(document).ready(function(){
	
	$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
	
	$('ul.gallery_demo').galleria({
		history   : true, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			image.css('display','none').fadeIn(1000);
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});
});
