// JavaScript Document
$(document).ready(function(){
	$('#homepage form.hp INPUT:text').focus(function(){
		if($(this).val()==$(this).attr('title')){
			$(this).val('');
		}
		$(this).css('color','#000');
	}).blur(function(){
		if($(this).val()==''){
			$(this).val($(this).attr('title'));
		}
		$(this).css('color','#ccc');
	});
	
	$('#homepage form.hp').submit(function(){
		//making the validation of inputs
		var ok=true;
		$('#homepage form.hp fieldset').children('.mandatory').each(function(){
			if($(this).val()==''){
				ok=false;
				alert('Please enter '+$(this).attr('title'));
			}
		});
		if(ok){
			$('#homepage form.hp fieldset').children('.email').each(function(){
				if(!$(this).val().match(/.+@.+\..+/)){
					ok=false;
					alert('Please enter correct '+$(this).attr('title'));
				} 
			});
		}
		
		if(ok){
			//sending message
			var post=$(this).serialize();
			$.post($(this).attr('action'),post,
				function(data){
					alert(data);
				});
		}
		
		return false;
		
	});
	
	$('#contact form').submit(function(){
		//making the validation of inputs
		var ok=true;
		$('#contact form fieldset .mandatory').each(function(){
			if($(this).val()==''){
				ok=false;
				alert('Please enter '+$(this).attr('title'));
			}
		});
		if(ok){
			$('#contact form fieldset .email').each(function(){
				if(!$(this).val().match(/.+@.+\..+/)){
					ok=false;
					alert('Please enter correct '+$(this).attr('title'));
				} 
			});
		}
		
		if(ok){
			//sending message
			var post=$(this).serialize();
			$('#contact form fieldset').fadeOut('slow');
			$.post('http://www.v9design.com/form.ajax.php',post,
				function(data){
					alert('aaa');
					$('#thanks').html(data).fadeIn('slow');
				})
		}
		
		return false;
		
	});
	
	var imgs=new Array('homepage_portfolio_1.jpg','homepage_portfolio_4.jpg','homepage_portfolio_2.jpg','homepage_portfolio_5.jpg','homepage_portfolio_3.jpg');
	
	//loading a random image for portfolio
	$('#portfolio_image').each(function(){
		k=$.cookie('homepage_image');
		while(k==(i=Math.round(Math.random()*4))){}
		$.cookie('homepage_image',i);
		$(this).html('<img src="images/homepage/'+imgs[i]+'" alt="" />');
	});
	
});


function fixPNG(element) {

	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		
		if (element.tagName=='IMG') {
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "images/blank.gif";
			}
		}
		
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";

			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}


