all_photos = [];
var current = 0;

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/************** CATEGORIES *************/

function listCategories()
{
	for(var i=0; i<all_photos.length; i++){
		document.writeln('<div class="categ-hold">');
		document.writeln('<span class="title" id="title'+i+'">' + all_photos[i][0] + "</span>");
		listCategPhotos(i);
		document.writeln('</div>');
	}
}

function listCategPhotos(categ_id)
{
	for(var i=0; i<all_photos[categ_id][2].length; i++){
		document.writeln('<a id="a'+categ_id+'_'+i+'" href="javascript:showPhoto('+categ_id+', '+i+');" class="t"><span>'+(i+1)+'</span><img width="11" src="images/b.gif"></a>');
	}
	document.writeln("<br><br>");
}

/***************************************/

var active_link  = '';
var active_categ = '';

function showPhoto(categ_id, photo_id)
{
	total      = all_photos[categ_id][2].length;
	folder     = all_photos[categ_id][1];
	photo_path = folder+"/"+all_photos[categ_id][2][photo_id];
	current    = photo_id;
	current_category = categ_id;
	
	// highlight active square
	if(active_link != ''){
		active_link.className = "t-visited";
	}
	active_link = MM_findObj("a"+categ_id+"_"+photo_id);
	active_link.className = "t-active";
	active_link.blur();
	
	// highlight active category name
	if(active_categ != ''){
		active_categ.className = "title";
	}
	active_categ = MM_findObj("title"+categ_id);
	active_categ.className = "active-categ";
	
	var target = MM_findObj("target_img");
	if(target!= null)
	{
		target.src = "images/wait.gif";
	}
	//displayPic(photo_path);
	MM_findObj("loadframe").src = "loader.html?p="+escape(photo_path);
}

function placePhoto(photo_path)
{
	displayPic(photo_path);
}

function next_photo()
{
	current++;
	if(current > total-1){
		current = 0;
	}
	showPhoto(current_category, current);
}

function prev_photo()
{
	current--;
	if(current < 0){
		current = total-1;
	}
	showPhoto(current_category, current);
}


function displayPic(photo_path)
{
	var target = MM_findObj("target_img");
	if(target!= null)
	{
		target.src = "images/wait.gif";
		target.src = photo_path;
	}
	works('m1');
}

function randomize()
{
	var categ_id = Math.floor(Math.random()*all_photos.length);
	current = Math.floor(Math.random()*all_photos[categ_id][2].length);
	showPhoto(categ_id, current);
	randomQuote();
}

/************* TOP MENUS **************/
var active = "";
var visible_div = "";

function activeMenu(id)
{
	if(active != ""){
		active.className = "";
	}
	active = MM_findObj(id);
	if(active != null)
	{
		active.className = "on";
	}
}

function works(mylink)
{
	
	if(visible_div != ""){
		visible_div.style.display = "none";
	}
	activeMenu(mylink);
}

function about(mylink)
{
	if(visible_div != ""){
		visible_div.style.display = "none";
	}
	visible_div = MM_findObj("about_div");
	visible_div.style.display = "block";
	activeMenu(mylink);
	
}

function contact(mylink)
{
	if(visible_div != ""){
		visible_div.style.display = "none";
	}
	visible_div = MM_findObj("contact_div");
	visible_div.style.display = "block";
	activeMenu(mylink);
}

/****************** QUOTES *******************/
function randomQuote()
{
	var qid = Math.floor(Math.random()*quotes_array.length);
	showQuote(qid);
}
function showQuote(id)
{
	var qd = MM_findObj("info_div");
	qd.innerHTML = '&#8220;'+quotes_array[id][0]+'&#8221;<br><span id="author">'+quotes_array[id][1]+'</span>'
}

window.setInterval("randomQuote()",10000);