/*
	javascript development
	============================
	website 	: 	zannos
	date 		: 	9-3-2009		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/



function rollover(id, hoverclass, content, imgid)
{
	document.getElementById(id).className = hoverclass;
	document.getElementById(id).innerHTML = content;
}

function rollout(id, defclass, imgid, imgname)
{
	document.getElementById(id).className = defclass;
	document.getElementById(id).innerHTML = '<img src="images/'+imgname+'" alt="" id="'+imgid+'" />';
}

function rollout_gr(id, defclass, imgid, imgname)
{
	document.getElementById(id).className = defclass;
	document.getElementById(id).innerHTML = '<img src="../images/'+imgname+'" alt="" id="'+imgid+'" />';
}

/* ========= FORM functions ========= */

function show_error(id)
{
	document.getElementById(id).style.background="#491406";
}

function clear_errors(which)
{
	for (i=0;i<document.forms[which].elements.length;i++)
	{
		if ( (document.forms[which].elements[i].type != "button") && (document.forms[which].elements[i].type != "reset") && (document.forms[which].elements[i].id!="fieldset") )
			document.forms[which].elements[i].style.background="none";
	}
}


function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
		return false;

   if(field.value.match(emailExp))
		   return true;
   else 
		   return false;
   
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailid)
{
	clear_errors(whichform);
	
	//check mandatory fields
	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if (document.getElementById(man[i]).value == "")
		{
			show_error(man[i]);
			alert ("You must fill all the mandatory fields (*)");
			return false;
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			return false;
		}
	}
	
	//check numeric fields
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
			
			if (isNaN (document.getElementById(numeric[i]).value))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}


function show_hide_div(id, action)
{
	if (action == 1)
		document.getElementById(id).style.display = "block";
	else
		document.getElementById(id).style.display = "none";
}



/* ============ intro ============== */


//var introtimer;


function showhide_intro(action) 
{		
	if (action == 1)	//html
	{
		document.getElementById('ncontent').style.display = "block";
		document.getElementById('jsintro').style.display = "none";
		scroller.init();
		
		document.location.href="#nointro";
	}
	else if (action == 2)	//intro
	{
		document.getElementById('ncontent').style.display = "none";
		document.getElementById('jsintro').style.display = "block";
	}
}
	
	
	

/*
function intro()
{
	if (document.getElementById('ncontent').style.display == "block")
	{
		document.getElementById('ncontent').style.display = "none";
		document.getElementById('jsintro').style.display = "block";
	}
					
	//--
	var speed = Math.round(1000 / 100);
	var timer = 0;
	//fade out
	changeOpac(0, 'introimg');
	
	document.getElementById('introimg').src = img_arr[imgp];
	
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'introimg')",(timer * speed));
		timer++;
	}
	//
	
	imgp = imgp + 1;
	if (imgp >= nm)
		imgp = 0;
		
	introtimer = setTimeout('intro()',3000);	//5 sec
}

*/


function changeOpac(opacity, id) 
{
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}



/* ==== gallery === */

function show_hide(id)
{
	var speed = Math.round(1000 / 100);
	var timer = 0;
		
	if (document.getElementById(id).style.display == "none")
	{
		for(i = 0; i <= 100; i++) {
			setTimeout("changeOpac(" + i + ",'"+id+"')",(timer * speed));
			timer++;
		}		
		document.getElementById(id).style.display = "block";
	}
	else
	{
		for(i = 100; i <= 0; i++) {
			setTimeout("changeOpac(" + i + ",'"+id+"')",(timer * speed));
			timer++;
		}		
		document.getElementById(id).style.display = "none";
	}
}

function show_next_img()
{
	document.getElementById('menu').style.display = "none";
	
	imgp = imgp + 1;
	if (imgp >= nm)
		imgp = 0;
		
	document.getElementById('gallery_img').style.background = "url("+ img_arr[imgp] +") no-repeat center fixed;";
	/*
	var speed = Math.round(1000 / 100);
	var timer = 0;
	//fade out
	changeOpac(0, 'gallery_img');
	
	document.getElementById('gallery_img').style.background = "url("+ img_arr[imgp] +") no-repeat center fixed;";
	
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'gallery_img')",(timer * speed));
		timer++;
	}
	//*/
}

function show_prev_img()
{
	document.getElementById('menu').style.display = "none";
	
	imgp = imgp - 1;
	if (imgp < 0)
		imgp = nm - 1;
		
	document.getElementById('gallery_img').style.background = "url("+ img_arr[imgp] +") no-repeat center fixed;";	
}


/*
function show_image(which)
{
	active_image= which;
	
	var id = which;
	
	document.getElementById('show_thumb').src = document.getElementById('thumb'+id).src;
	for (i=1;i<=how_many;i++)
	{
		if (i<=total_img+1)
			document.getElementById('thumb'+i).className = "gthumb";
	}
	//alert('thumb'+id);
	document.getElementById('thumb'+id).className = "gthumb_loc";
	
	
	//--
	var speed = Math.round(800 / 100);
	var timer = 0;
	//fade out
	changeOpac(0, 'show_thumb');
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'show_thumb')",(timer * speed));
		timer++;
	}
	
}*/