function swip (elementInput, swipFrom, swipTo)
{
if (elementInput.value == swipFrom) elementInput.value = swipTo;
}

$(document).ready(function() {

	$('#contact_form_trigger').click(function(){
		$('#contact_form  form').animate({
		    left: '50'
		  }, 500);
		  return false;
	})
	
	$('.cf-view').click(function(){
		$('#contact_form  form').animate({
		    left: '50'
		  }, 500);
		  return false;
	})
	
	$('#close_contact_form').click(function(){
		$('#contact_form  form').animate({
		    left: '-407'
		  }, 500);
		  
		 return false;
	})
	
	$('#contact_form  form').submit(function(){
		
		var form_data = $(this).serialize();
		$.ajax({
		   type: "POST",
		   url: '/ajax-contact-form',
		   data: form_data,
		   success: function(msg)
		   {
				$('#contact_form .form_cnt').html(msg);
		   }
		 });
		 
		 return false;
		
	})
	
	
	$('#up').click(function(){
		$('html, body').animate({scrollTop: '0px'}, 800);
		return false;
	});

 
  $("img.shadow-img").each(function (index, domEle) {
    $(domEle).wrap('<div class="shadow-img-wrap"></div');

    if ($(domEle).hasClass('align-left')) {
        $(domEle).removeClass('align-left')
        $(domEle).parent().addClass('align-left');           
    }
    if ($(domEle).hasClass('align-right')) {
        $(domEle).removeClass('align-right')
        $(domEle).parent().addClass('align-right');           
    }
  });
  

	$('input.button').hover(function(){
		$(this).addClass('b_hover');
	},
	function(){
	$(this).removeClass('b_hover');
	}); 
	
	$('.mailform select').live('change',function(){

		if($(this).val() == 'ine')
		{
			$(this).after('<input class="select_other" id="'+$(this).attr('id')+'ine" type="text" name="'+$(this).attr('name')+'" />');
		}
		else
		{
			$('#'+$(this).attr('id')+'ine').remove();
		}
		
	})
	
	$('#contact_form label.infield').each(function()
	{
		var label_value = $(this).text();
		var label_target = $('#'+ $(this).attr('for'));
		
		if('' === label_target.val()){
			label_target.val(label_value);
		}
		label_target.attr('title',label_value);
		$(this).hide();
		
		label_target.focus(function() {
	    	if(label_target.val() === label_target.attr('title')) {
		      label_target.setCursorPosition(0);				label_target.val('');
			  
			  label_target.css('color','#e3dac7');
			  //label_target.val('');
		    }
		});
		
		label_target.keypress(function() {
	    	 label_target.css('color','#e3dac7');
			if(label_target.val() === label_target.attr('title')) {
			  label_target.val('');
		    }
		});
		
		
		label_target.blur(function() {
		    label_target.css('color','#e3dac7');
			if(label_target.val() === '') {
		      
			  label_target.val(label_target.attr('title'));
		    }
		});

	})
	
	$.fn.setCursorPosition = function(pos) {
	  this.each(function(index, elem) {
	    if (elem.setSelectionRange) {
	      elem.setSelectionRange(pos, pos);
	    } else if (elem.createTextRange) {
	      var range = elem.createTextRange();
	      range.collapse(true);
	      range.moveEnd('character', pos);
	      range.moveStart('character', pos);
	      range.select();
	    }
	  });
	  return this;
	};
});   

