// SiteMix JavaScript Document

// mobile uagents detecting
var mobile = false;
var androidsys = false;

var deviceIphone = "iphone";
var deviceIpod = "ipod";
var deviceS60 = "series60";
var deviceSymbian = "symbian";
//var engineWebKit = "webkit";
var deviceAndroid = "android";
var deviceWinMob = "windows ce";
//var deviceBB = "blackberry";
var devicePalm = "palm";

var uagent = navigator.userAgent.toLowerCase();

if (uagent.search(deviceIphone) > -1) {
	mobile = true;
} else if (uagent.search(deviceIpod) > -1) {
	mobile = true;
} else if (uagent.search(deviceAndroid) > -1) {
	mobile = true;
	androidsys = true;	
} else if (uagent.search(deviceWinMob) > -1) {
	mobile = true;
} else if (uagent.search(devicePalm) > -1) {
	mobile = true;
} else if (uagent.search(deviceS60) > -1) {
	mobile = true;
} else if (uagent.search(deviceSymbian) > -1) {
	mobile = true;
};



$(document).ready(function() {
						   
	if (!androidsys) {
		$('#buyandr').attr({
						   href: 'colorix_slideme.html?iframe=true&width=340&height=500',
						   title: 'Colorix Android Purchase Guide',
						   rel: 'prettyPhoto[iframes]'
						   });
	};						
	
	if (!mobile) {
	  $("a[rel^='prettyPhoto']").prettyPhoto({
										 opacity: 0.3,
										 padding: 20
										 });
	};
   
	var iphone = $('#topcontainer div.iphone');
	var android = $('#topcontainer div.android');
	
	$('div.android p').rotator();
	$('div.iphone p').rotator();
	
	$(android).children('.topcontright').hide();
	
	$('#android').click(function() {
								 if (!$('body').hasClass('android')) 
								 {	
									 $(android).children('.topcontright').show();
									 $(iphone).children('.topcontright').hide();
								 	 $(android).insertBefore(iphone);
									 $('body').removeClass().addClass('android');
									 
								 }
								 });
	$('#iphone').click(function() {
								if (!$('body').hasClass('iphone'))
								{
									$(android).children('.topcontright').hide();
									$(iphone).children('.topcontright').show();									
									$(iphone).insertBefore(android);
									$('body').removeClass().addClass('iphone');
								}
								});

// turn on pngFix
//	$(document).pngFix(); 
	
	
/******************/
/* form show/hide */
/******************/	
	function showFeedback() {
		$('#feedback_container').animate({width: 298}, 700);
	};
	function hideFeedback() {
		$('#feedback_container').animate({width: 34}, 700);		
	};
	$('#feedback_container a').toggle(
									  function() {
										  showFeedback();
										  }, 
									  function() {
										  hideFeedback();
										  });
	
/*******************/
/* form validation */
/*******************/
	function showProgress() {		
		$('#fsbm').fadeOut('fast', function() {
										  		$('#formprogress').show();
											  });
	};
	function hideProgress(success) {
		if (success == true) {
		// submit success			
		function waitMoment() {
			clearTimeout(wait02);
		var message = 'Message Send.<br />Thank you for your feedback!';
			$('#formprogress').fadeOut('normal', function() {
														  $('#formmessage').remove();
														  $('#feedback_container form').append('<p id="formmessage">' + message + '</p>');
														  $('#formmessage').fadeIn();
														  });

			function activateForm() {
				clearTimeout(wait);
				$('#formmessage').fadeOut('normal', function() {
																$('#fsbm').fadeIn();
																$('#FeedbackForm input, #FeedbackForm textarea').attr({value: ''});
															});
			};
			wait = setTimeout(activateForm, 3500);
		};
			wait02 = setTimeout(waitMoment, 500);
			
		} else {
		// submit failed
		var message = 'Something went wrong...<br />Please <span>try again</span>!';
			$('#formprogress').fadeOut('normal', function() {
														  $('#formmessage').remove();
														  $('#feedback_container form').append('<p id="formmessage">' + message + '</p>');
														  $('#formmessage').fadeIn();
														  $('#formmessage span').click(function() {
																						   		$('#formmessage').fadeOut('fast', function() {
																																$(this).remove();
																																$(this).unbind();
																																$('#FeedbackForm').submit();
																																		   });
																								});

														  });

		};
	};
	$('#FeedbackForm').validate({
								errorElement: "em",
								errorPlacement: function(error, element) {
								   error.appendTo( element.prev("label") );
								 },
								 rules: {
									 name: {
										 minlength: 2
									 }
								 },
								submitHandler: function(form) {
									//$(form).ajaxSubmit();
									
/****************************/
/* form submitting via Ajax */
/****************************/	
 $.ajax({
   type: "GET",
   url: "comment.php",
   data: "s="+escape($('#name').val())+"&b="+escape($('#message').val())+"&f="+$('#email').val(),
   success: function(msg){
     if (msg == '0'){
         hideProgress(true);
     }else{
         hideProgress(false);
     }
   }
 });
	  // show submiting progress
	  showProgress();
	  return false;
  }

  });
});


