$(document).ready(function(){	
	$("#slider").azzihamSlider();
	
	$.smoothAnchors(1000, 'swing', true);
	
	$('#frame-contact .quick').click(function(){
		contactForm();
	});
	
	$('#frame-work li').each(function(){
		$(this).click(function(e){
			var url = $(this).attr('uri');
			showGalleryDetail(url);
		});
	});
});

function showImage(trigger){
	var htm='';
	htm=htm+'<div class="window-image"><img src="'+trigger.attr('src')+'" /></div>';
	htm=htm+'<div class="window-overlay"></div>';
	
	$("body").append(htm);
	$('.window-overlay').css({position:'absolute',left:0,top:0,right:0,width:$('body').width()+'px',height:$('body').height()+'px'});
	$('.window-image').css({position:'fixed',zIndex:1000,textAlign:'center',top:'100px',width:$('body').width()+'px'});
	$('.window-image img').css({cursor:'pointer'});
		
	$('.window-overlay').dblclick(function(){
		$('.window-overlay').remove();
		$('.window-image img').remove();
	});
	
	$('.window-image').dblclick(function(){
		$('.window-overlay').remove();
		$('.window-image img').remove();
	});
	
	$('.window-image img').click(function(){
		$('.window-overlay').remove();
		$('.window-image img').remove();
	});
}

function contactForm()
{
	var htm='';
	htm=htm+'<div class="window-overlay"></div>';
	htm=htm+'<div id="popcontact">';
	htm=htm+'	<div class="top"><a id="popcloser">&nbsp;</a></div>';
	htm=htm+'	<div class="middle">';
	htm=htm+' <form id="form-contact" onsubmit="sendContact(); return false;">';
	htm=htm+' <table width="100%" cellpadding="4">';
	htm=htm+'	<tr><td colspan="2">Please kindly fill the forms to leave a message</td></tr>';
	htm=htm+' <tr><td>Name*</td><td><input type="text" name="val_name" id="val_name" maxsize="30" style="width:300px;" /></td></tr>';
	htm=htm+' <tr><td>Email*</td><td><input type="text" name="val_email" id="val_email" maxsize="50" style="width:300px;" /></td></tr>';
	htm=htm+' <tr><td>Phone</td><td><input type="text" name="val_phone" id="val_phone" maxsize="20" style="width:100px;" /></td></tr>';
	htm=htm+' <tr><td>Message*</td><td><textarea name="val_message" style="width:300px;height:80px;" maxsize="200"></textarea></td></tr>';
	htm=htm+' <tr><td>&nbsp;</td><td align="right" class="send-contact"><img src="images/contact_send.gif" id="csend" /><span id="cmsg"></span></td></tr>';
	htm=htm+' </table>';
	htm=htm+' </form>';
	
	htm=htm+' </div>';
	htm=htm+'	<div class="bottom"></div>';
	htm=htm+'</div>';
	
	$("body").append(htm);
	$('#popcontact').css({position:'fixed',left:0,right:0,top:100+'px',marginRight:'auto',marginLeft:'auto'});
	$('.window-overlay').css({position:'absolute',left:0,top:0,right:0,width:$('body').width()+'px',height:$('body').height()+'px'});
	
	$('#popcloser').click(function(){
	  $('.window-overlay').fadeOut('normal', function() {
			$('#popcontact').remove();
			$('.window-overlay').remove();
	  });
	});
	
  $('#csend').click(function(){
  	sendContact();
  });
}

function sendContact()
{
	$('#cmsg').html('Sending email, please wait....');
	$('#csend').hide();
	
	$.ajax({
		url:"contact.php",
		type:"post",
		data:$("#form-contact").serialize(),
		dataType:'json',
		success:function(data){
			
			$('#cmsg').html('');
			$('#csend').show();
			
			if(data.status=='success'){
				$('#popcloser').click();
				alert(data.msg);
			}else{
				alert(data.msg);
			}
		}
	});
}

function showGalleryDetail(xmlurl)
{
		var html='';
		html=html+'';

		html=html+'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="603" height="258" id="gal" align="middle">';
		html=html+'	<param name="allowScriptAccess" value="sameDomain" />';
		html=html+'	<param name="allowFullScreen" value="false" />';
		html=html+'	<param name="flashVars" value="XMLFile='+xmlurl+'">';
		html=html+'	<param name="movie" value="js/PhotoFlowGalleryDemo.swf" />';
		html=html+'	<param name="quality" value="high" />';
		html=html+'	<param name="bgcolor" value="#ffffff" />';
		html=html+'	<embed src="js/PhotoFlowGalleryDemo.swf" quality="high" bgcolor="#ffffff" width="900" height="500" name="gal" flashvars="XMLFile='+xmlurl+'" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html=html+'</object>';

		Boxy.alert(html);
		$(".boxy-wrapper").css({top:5+"px"});
		
		$(".answers").html('<img src="images/close.gif" border="0" id="popclose" />');
		$(".answers").css({textAlign:"center",color:"#FFF",marginTop:"5px"})
		$("#popclose").css({cursor:"pointer"});
		$("#popclose").click(function(){
			popClose('boxy-wrapper');
		})
}

function popClose(boxy)
{
	$("."+boxy).remove();
	$(".boxy-modal-blackout").remove();
}