//general
var options1 =
		{									
		showEffect:'show',
		hideEffect:'fadeout',
		fadeoutSpeed: 'slow',
		title :false,
		zoomType:'reverse'

		}

var ns4=document.layers?1:0 
var ie4=document.all?1:0 
var ns6=document.getElementById&&!document.all?1:0
var isMinIE5 = (ie4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;

var no = 0;
var fadeined = 3;
var gemstones_alpha = 0;

if(ns6){	
	document.write('<link href="css/style_ns.css" rel="stylesheet" type="text/css">');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//scroll bar 

function moveHandler(e){	 
  if (e == null) { e = window.event } 
  if (e.button<=1&&dragOK){
	 
	  if(e.clientY-dragYoffset >= 0 && e.clientY-dragYoffset <= sh){			
		savedTarget.style.marginTop=e.clientY-dragYoffset+'px';
	
		vidPoll.style.marginTop = -((e.clientY-dragYoffset)/sh)*(hd-(sh));
	  }
	// savedTarget.style.top=e.clientY-dragYoffset+'px';
	 return false;
  }
}

function cleanup(e) {
  document.onmousemove=null;
  document.onmouseup=null;
  posT = savedTarget.style.marginTop.replace('px','');
	posT = parseInt(posT/2);
	savedTarget.style.marginTop = posT * 2;	
  dragOK=false;
}

function dragHandler(e){
 
  var htype='-moz-grabbing';
  if (e == null) { e = window.event; htype='move';} 
  var target = e.target != null ? e.target : e.srcElement;
  orgCursor=target.style.cursor;
  if (target.className=="speedbar1") {
	 savedTarget=target;       
	 dragOK=true;
	 //dragXoffset=e.clientX-parseInt(vidPaneID.style.marginLeft);
	 dragYoffset=e.clientY-parseInt(vidPaneID.style.marginTop);
	 document.onmousemove=moveHandler;	 
	 document.onmouseup=cleanup;
	 return false;
  }
}


//ajax

function GetXmlHttpObject(){
	var xmlHttp=null;
	if (window.XMLHttpRequest)  {// code for Firefox, Opera, IE7, etc.	  
	  xmlHttp=new XMLHttpRequest(); 

	}else if (window.ActiveXObject)  {// code for IE6, IE5
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

	}
	return xmlHttp;
}


function loadXML(url, state){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp != null)  {	
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4) {// 4 = "loaded"		
				if (xmlHttp.status==200)  {// 200 = "OK"
					if(state != "thx" && state != "gtxt"){
						document.getElementById('ag_content').innerHTML=xmlHttp.responseText;

					}else if(state == "gtxt"){
						document.getElementById('gstxt').innerHTML=xmlHttp.responseText;

					}else{
						document.getElementById('img2').innerHTML = thankyou;
						img2_alpha = 0;
						nfadein('img2');
					}
				}
			}
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}


function load(obj, link, state){

	if(obj == "gemstones"){	
		loadXML(link, state);
		this[obj+'_alpha'] = 0;
		nfadein(obj);

	}else if(state == "gtxt"){
		document.getElementById('gstxt').innerHTML="";
		loadXML(link, state);
		this[obj+'_alpha'] = 0;
		nfadein(obj);

	}else if(state == "thx"){
		n=document.apply.name.value;
		e=document.apply.email.value;
		loadXML(link+"?n="+n+"&e="+e, state);
		document.getElementById('img2').innerHTML = '<img src="images/mdesign2009_04.gif">';
	
	}else{		
		this[obj+'_alpha'] = 100;
		nfadeout(obj, link, state);
		if(state != "apply"){
			fadeined = 0;
		}
		
	}
}


function nfadeout(obj, link, state){	
	if(this[obj + '_alpha'] > 0){		
		if(ie4){			
			eval(obj+".filters.alpha.opacity="+this[obj + '_alpha']);
		}else{
		
			document.getElementById(obj).style.opacity = this[obj + '_alpha']/100;
		}
		this[obj + '_alpha'] -=10;
		setTimeout("nfadeout('"+obj+"','"+link+"','"+state+"')","30");
	}else{		
		this[obj + '_alpha']= 0;

		if(ie4){
			eval(obj+".filters.alpha.opacity="+this[obj + '_alpha']);			
		}else{
			document.getElementById(obj).style.opacity = this[obj + '_alpha']/100;
		}

		document.getElementById(obj).style.display = 'none';
		
		
		if(obj != "gemstones" && state != "apply" && state != "thx" && state != "gtxt"){
			if(obj.indexOf('text') != -1){			
				document.getElementById(obj).innerHTML = link;
				nfadein(obj);
			}else{
				Preloader = new Image();
				Preloader.onload = function(){		
					Preloader.onload = null;
					if(state != "jzoom" && state != ""){						
						document.getElementById(obj).innerHTML = '<a href="javascript:popup(\'enlarge.php?id='+state+'&TB_iframe=true&height=410&width=570\')" class="thickbox"><img src="'+link+'" border="0"></a>';
					}else if(state == "jzoom"){
						document.getElementById(obj).innerHTML = '<a href="'+link.replace('thumbnails/s_','photo/')+'" class="jqzoom"><img src="'+link+'" border="0"></a>';
						no++;
					}else{
						document.getElementById(obj).innerHTML = '<img src="'+link+'" border="0">';
						
					}
					nfadein(obj);
				}

				Preloader.src = link;
			}
		}else if(state == "apply"){
			document.getElementById(obj).innerHTML = applyform;
			nfadein(obj);
		
		}


	}	
}

function nfadein(obj){
	
	document.getElementById(obj).style.display = 'block';
	if(this[obj + '_alpha'] < 100){		

		if(ie4){
			eval(obj+".filters.alpha.opacity="+this[obj + '_alpha']);
		}else{
			document.getElementById(obj).style.opacity = this[obj + '_alpha']/100;
		}
		this[obj + '_alpha'] +=10;
		setTimeout("nfadein('"+obj+"')","20");
	}else{
		if(obj == "gemstones"){
			hd = document.getElementById('ag_content').offsetHeight;	
			vidPaneID = document.getElementById('poll_speedbar');
			vidPoll = document.getElementById('ag_content');
			
			sh = 100;
			document.onmousedown=dragHandler;
		}else{
			fadeined++;
			
		}
		
		obj_alpha = 100;
		if(ie4){
			eval(obj+".filters.alpha.opacity="+this[obj + '_alpha']);
		}else{
			document.getElementById(obj).style.opacity = this[obj + '_alpha']/100;
		}
		
		
		if(no == 2){
			$(".jqzoom").jqzoom(options1);
		}else if(no == 4){			
			$(".jqzoom").jqzoom(options1);		
		}
		
	}	
	
}

function textbox(){	
	if(document.login.pw.value == 'enter password'){
		document.getElementById('enpw').innerHTML = '<input type="password" name="pw" class="gold_border" onMouseOver=this.select() onblur="textbox()">';
	}else if(document.login.pw.value == ''){
		document.getElementById('enpw').innerHTML = '<input type="text" name="pw" value="enter password" class="gold_border" onclick="textbox()">';
	}
}


function chgimg(state){	
	if(fadeined >= 3){
		if(gemstones_alpha == 100){
			nfadeout('gemstones', '', '');
		}

		var total = img.length;	
		if(state == "left"){			
			if(no == total){
				no = 0;
			}
			setTimeout("load('img1','images/thumbnails/s_"+img[no]['p']+"','"+img[no]['i']+"')","0");						
			setTimeout("load('img2','images/thumbnails/s_"+img[no+1]['p']+"','"+img[no+1]['i']+"')","200");
			setTimeout("load('img3','images/thumbnails/s_"+img[no+2]['p']+"','"+img[no+2]['i']+"')","400");

			if(no >= (total-4)){
				no = 0;
			}else{
				no += 3;
			}

		}else if(state == "right"){
			
			if(no <= 3){
				no = total;
			}else{
				no -= 3;
			}
			setTimeout("load('img1','images/thumbnails/s_"+img[no-3]['p']+"','"+img[no-3]['i']+"')","0");			
			setTimeout("load('img2','images/thumbnails/s_"+img[no-2]['p']+"','"+img[no-2]['i']+"')","200");
			setTimeout("load('img3','images/thumbnails/s_"+img[no-1]['p']+"','"+img[no-1]['i']+"')","400");

		}
	}
}

function popup(link){
	$("#TB_window").remove();
	$("body").append("<div id='TB_window'></div>");
	tb_show('', link,'');
}

function chk(act){
		err = "";		
		if(document.mailform.sender.value == ""){
				err += "please fill sender's name\n\r";
			}
		if(document.mailform.sendermail.value == ""){
			err += "please fill sender's mail\n\r";
		
		}else{
			if(document.mailform.sendermail.value.indexOf("@") == -1 || document.mailform.sendermail.value.indexOf(".") == -1){
				err += "sender's email format error\n\r";
			}
		}		

		if(act == "ecard"){			
			if(document.mailform.recipient.value == ""){
				err += "please fill recipient's name\n\r";
			}
			if(document.mailform.recipientmail.value == ""){
				err += "please fill recipient's mail\n\r";
			}else{
				if(document.mailform.recipientmail.value.indexOf("@") == -1 || document.mailform.recipientmail.value.indexOf(".") == -1){
					err += "recipient's email format error\n\r";
				}
			}
			document.mailform.action.value = "ecard";
		}else if(act == "enquiry"){
			if(document.mailform.msg.value == ""){
				err += "please fill enquiry\n\r";
			}
			document.mailform.action.value = "enquiry";
		
		}
		if(err != ""){
			alert(err);
			return;
		}
		document.mailform.submit();
}

function chkout(){
	parent.location="checkout.php";
}

var applyform = '<table width="100%" height="125px" border="0" cellspacing="0" cellpadding="4" bgcolor="#A07F4A">'+
'<form name="apply" method="post">'+
'<tr>'+
'<td>Name: </td>'+
'<td><input type="text" name="name" class="apply gold_border"></td>'+
'</tr>'+

'<tr>'+
'<td>Email: </td>'+
'<td><input type="text" name="email" class="apply gold_border"></td>'+
'</tr>'+

'<tr>'+
'<td></td>'+
'<td><a href="javascript:load(\'img2\',\'sendapply.php\',\'thx\')"><span class="btn">Submit</span></a></td>'+
'</tr>'+

'</form>'+
'</table>';

var thankyou = '<table width="100%" height="125px" border="0" cellspacing="0" cellpadding="3" bgcolor="#A07F4A">'+
'<tr>'+
'<td align="center">Thank you for signing up.<br>You will receive the updated password within 24 hrs.<br><br>Click below to the current design preview.<br>Enjoy!</td>'+
'</tr>'+
'</table>';
