//local
//var rootPath = 'http://laidlow.dyndns.org/sites/studioya.com';
var imagesPerRow = 14;
//online
var rootPath = 'http://www.studioya.com/site';

function updateLightbox(cont) {
	var url = rootPath+'/scripts/updateSession.php?type=set&cookie=lightboxes&cont='+cont;
	document.getElementById('addToLightbox').innerHTML = '<img src="'+rootPath+'/images/ajax_loader.gif" />';
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('addToLightbox').innerHTML = '<img src="'+rootPath+'/images/lightbulb_add.png" alt=\"Added to Lightbox!\" title=\"Image Has Been Added to the Lightbox!\"/>';
			document.getElementById('addToLightbox').style.cursor = "default";
		}
	});
}

function updateLightbox2(cont,path) {
	
	var url = rootPath+'/scripts/updateSession.php?type=set&cookie=lightboxes&cont='+cont;
	document.getElementById('btns_'+cont).innerHTML = '<img src="'+rootPath+'/images/ajax_loader.gif" />';
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			 document.getElementById('btns_'+cont).innerHTML = '<img src="'+rootPath+'/images/lightbulb_add.png" alt="Added to Lightbox!" title="Image Has Been Added to the Lightbox!"/>&nbsp;&nbsp;<img src="images/magnifier.png" alt="View Full Size" title="View Full Size" onclick="popUpImage(\''+path+'\');" style="cursor:pointer"/>';
			document.getElementById('al_'+cont).style.cursor = "default";
		}
	});
}


function updateContactQuery(cont) {
	
	var url = rootPath+'/scripts/updateSession.php?type=set&cookie=contactQuery&cont='+cont;
	document.getElementById('cq_'+cont).src = rootPath+'/images/ajax_loader.gif';
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('cq_'+cont).src = rootPath+'/images/email_attach.png';
			document.getElementById('cq_'+cont).title = 'Added to Contact Query';
			document.getElementById('cq_'+cont).alt = 'Added to Contact Query';
			document.getElementById('cq_'+cont).onclick = 'void()';
			document.getElementById('cq_'+cont).style.cursor = "default";
		}
	});
}

function removeFromLightbox(cont) {
	document.getElementById('dl_'+cont).src = rootPath+'/images/ajax_loader.gif';
	var url = rootPath+'/scripts/updateSession.php?type=del&cookie=lightboxes&cont='+cont;
	
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('img_'+cont).innerHTML = "";
			document.getElementById('img_'+cont).style.display = "none";
		}
	});
}

function selectImageInContact(obj){
	navRoot = document.getElementById("contactThumbsHolder");
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		document.getElementById(node.id).style.visibility='hidden';
	}
	document.getElementById(obj).style.visibility='visible';
}

function removeFromContactQuery(obj){
	
	document.getElementById('btns_'+obj).src = rootPath+'/images/ajax_loader.gif';
	var url = rootPath+'/scripts/updateSession.php?type=del&cookie=contactQuery&cont='+obj;
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('item_'+obj).style.display='none';
			document.getElementById('img_'+obj).style.display='none';
		}
	});
}

function getImageData(path) {
	var url = rootPath+'/scripts/getImageData.php?path='+path;
	document.getElementById('imageInfo').innerHTML = '';
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('imageInfo').innerHTML = transport.responseText;			
		}
	});
	
}

function submitSearch(cont,arch) {
	if(arch==true){
		var url = rootPath+'/scripts/search.php?arch=true&search='+cont;
	} else {
		var url = rootPath+'/scripts/search.php?arch=false&search='+cont;
	}
	
	
	if(cont=='%'){
		document.getElementById('testinput').value = '';
	}
	
	document.getElementById('searchResults').innerHTML = '<div align="center"><strong><img src="'+rootPath+'/images/ajax_loader.gif" /><br/><br/>Searching</strong></div>';
	
	new Ajax.Request(url, {
		onSuccess: function(transport) {
			document.getElementById('searchResults').innerHTML = transport.responseText;
		}
	});
}


function submitContactForm(){
	form_name = document.getElementById('form_name').value;
	form_email = document.getElementById('form_email').value;
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	
	if(form_name == '' && !filter.test(form_email)) {
		alert("Please fill in a valid e-mail address and a name.");
	} else if(form_name == '') {
		alert("Please fill in a name.");
	} else if(!filter.test(form_email)) {
		alert("Please fill in a valid e-mail address.");
	} else {
		//document.getElementById('form_email').value = "none...";
		document.getElementById('contactForm').submit();
		document.getElementById('contactFormDiv').innerHTML = '<div align="center"><strong><img src="'+rootPath+'/images/ajax_loader.gif" /><br/><br/>Sending Contact Form</strong></div>';
	}
}



function viewLargeImage(imgSrc,count){
	document.getElementById('addToLightbox').innerHTML = '<img src="'+rootPath+'/images/lightbulb.png" alt=\"Add to Lightbox\" title=\"Add to Lightbox\"/>';
	document.getElementById('addToLightbox').style.cursor = "pointer";
	document.getElementById('largeImage').innerHTML = '<img style="cursor:pointer;border:1px solid #c0bc5b;" id="imgLarge" src="'+rootPath+'/gd/phpThumb.php?src='+imgSrc+'&w=429&h=429" border="0" onclick="popUpImage(\''+imgSrc+'\');"/>';	
	var showThis = checkThumbsPage(count);
	if((totalImages-1)>imagesPerRow)showThumbsPage(showThis);
	(count==currentImage) ? crnt = null : crnt = currentImage;
	setThumb(count,crnt,'1px solid #4e2200','1px solid #c0bc5b');
	getImageData(imgSrc);
}

function checkThumbsPage(id){
	maxn = imagesPerRow;
	pg = 1;
	tmp = 0;
	for(tt=0;tt<totalImages;tt++){
		tmp++;
		if(tmp>=maxn){
			pg++;
			tmp=0;
		}
		if((tt+1)==id){
			loc = pg;	
		}
	}
	
	if(id==0)loc=1;
	return loc;

}


function setThumb(id,prevID,style1,style2){
	if(prevID==totalImages)prevID=0;
	if(prevID<0)prevID=totalImages-1;
	document.getElementById('img_'+id).style.border=style1;
	if(prevID!=null)document.getElementById('img_'+prevID).style.border=style2;
	var imgSrc = document.getElementById('img_'+id).src;
	createCookie('currentImage',id,1);
}

function showNext(val){
	document.getElementById('addToLightbox').innerHTML = '<img src="'+rootPath+'/images/lightbulb.png" alt=\"Add to Lightbox\" title=\"Add to Lightbox\"/>';
	document.getElementById('addToLightbox').style.cursor = "pointer";
	var ShowThisOne = currentImage-0+val;
	if(ShowThisOne > totalImages-1) currentImage = -1;
	if(ShowThisOne < 0) currentImage = totalImages;
	var imgSrc = document.getElementById('img_'+(ShowThisOne)).src;
	document.getElementById('img_'+(ShowThisOne)).onclick();
	createCookie('currentImage',ShowThisOne,1);
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function popUpImage(path){
	document.getElementById('mainCover').style.visibility = 'visible';
	document.getElementById('popUpImage').style.visibility = 'visible';
	document.getElementById('popUpImage').innerHTML = '<table width="100%" height="100%" border="0"><tr><td align="center" valign="middle"><img id="poppedImage" src="'+rootPath+'/gd/phpThumb.php?src='+path+'&w=800&h=600&zc=0" alt="Click to Close" title="Click to Close" /></td></tr></table>';
}

function popDownImage(){
	document.getElementById('mainCover').style.visibility = 'hidden';
	document.getElementById('popUpImage').style.visibility = 'hidden';
	document.getElementById('popUpImage').innerHTML = '';
}


function showThumbsPage(id){
	for(i=1;i<thumbPages+1;i++){
		document.getElementById('thumbsPage_'+i).style.display='none';
		document.getElementById('pageSwitch_'+i).style.backgroundColor='#ffffff';
	}
	document.getElementById('thumbsPage_'+id).style.display='block';
	document.getElementById('pageSwitch_'+id).style.backgroundColor='#bbff33';
	currentThumbsPage = id;
}

var posx;
var posy;
function getMouse(e){
	posx=0;
	posy=0;
	var ev=(!e)?window.event:e;//Moz:IE
	if (ev.pageX){posx=ev.pageX;posy=ev.pageY;}//Mozilla or compatible
	else if(ev.clientX){posx=ev.clientX;posy=ev.clientY}//IE or compatible
	else{return false}//old browsers
	//document.getElementById('HoverImgHolder').innerHTML='X='+posx+' Y='+posy;
	document.getElementById('HoverImgHolder').style.left = posx+15+'px';
	document.getElementById('HoverImgHolder').style.top = posy+15+'px';
}

function showFloater(path){
	document.getElementById('HoverImgHolder').style.display = 'block';
	document.getElementById('HoverImgHolder').innerHTML = '<img src=\"'+path+'\"/>';
}
function hideFloater(){
	document.getElementById('HoverImgHolder').style.display = 'none';
	document.getElementById('HoverImgHolder').innerHTML=''
}


function getKeywords(){
	if(javaPage=="archive" || javaPage=="search"){
			var options = {
			script:rootPath+"/scripts/keywords.php?page="+javaPage+"&json=true&",
			varname:"input",
			json:true,
			callback: function (obj) { }
		};
		var as_json = new AutoSuggest('testinput', options);
		var options_xml = {
			script:rootPath+"/scripts/keywords.php?",
			varname:"input"
		};
	}
}

function initMenuIE(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		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", "");
				}
			}
		}
	}
}

function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // init
	initMenuIE();
	getKeywords();	
}
function about_change_tab(id){
 for (i=5 ; i < 9 ; i++) {
	 if (i==id) {
 		about_class = 'about_nav_tab tab_selected';
 		about_display = 'block';
	 } else {
	 	 about_class = 'about_nav_tab';
		 about_display = 'none';
 	 }

 	$('about_nav_tab'+i).className = about_class;
 	$('about_content_tab'+i).style.display = about_display;
 }

}