/*!
 *
 * script.js v3.0
 * http://auraserea.ro/
 *
 * Copyright 2011, Zeno Popovici
 *
 */

	$(document).ready(function() {
		// initialize the banners
	    $("div.banners").scrollable({ 
	    	keyboard: true, 
	    	circular: true, 
	    	easing: "swing", 
	    	next: ".next", 
	    	prev: ".prev", 
	    	disabledClass: "disabled" 
	    }).autoscroll({ 
	    	autoplay: true, 
	    	interval:10000, 
	    	autopause:true 
	    }).navigator({navi:".dot-nav", indexed:false, history: true});
	    
		$("a.lightbox").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false,
			'opacity'		:	true,
			'overlayShow'	:	true,
			'titleShow'		:	false,
			'hideOnContentClick': true
		});
			
		$("a.lightvideo").click(function() { 
			$.fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'padding'		: 0,
				'autoScale'		: false,
				'titleShow'		:	false,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				   	'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
			return false;
		});
/*		if(!$.browser.msie) {
			// Ajax pagination 
			$('.pagination a').live('click', function(e){
				e.preventDefault();
				var link = jQuery(this).attr('href');
				//Loading animation
				$('.loading').fadeIn(500);
				//Set progress cursor
				$('body').css("cursor", "progress");
				//Load Ajax content
				$('.ajax').fadeOut(700).load(link + ' .ajax-content', function(){ 
					$('.ajax').fadeIn(700); 
					$('.loading').fadeOut(500); 
					$('body').css("cursor", "default")
				});
	
				//Re-initialize FancyBox after Ajax Load
				$("a.lightbox").live("click", function(event) {
					event.preventDefault();
					$(this).filter(':not(.fb)').fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	600, 
					'speedOut'		:	200, 
					'overlayShow'	:	false,
					'opacity'		:	true,
					'overlayShow'	:	true,
					'titleShow'		:	false,
					'hideOnContentClick': true
					}).addClass('fb');
					$(this).triggerHandler('click');
	    		});
	    	});
		}
*/	
		// Fix time on site for Google Analytics
		(function (tos) {
	  		window.setInterval(function () {
		    	tos = (function (t) {
		      		return t[0] == 50 ? (parseInt(t[1]) + 1) + ':00' : (t[1] || '0') + ':' + (parseInt(t[0]) + 10);
		    	})(tos.split(':').reverse());
		    	_gaq.push(['_trackEvent', 'Time', 'Log', tos]);
	  		}, 10000);
		})('00');
	
	});
	//E-mail validation
	function validate_email(email) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	    return reg.test(email);
	}
	
	//Comment submit
	$('#comment-form').submit(function(){
		var error = false;	
		if ($('#comment-form #author').val() == '' && $('#comment-form #author').length) {
			$('#comment-form #author').addClass('error');
			error = true;
		}
		if (!validate_email($('#comment-form #email').val()) && $('#comment-form #email').length) {
			$('#comment-form #email').addClass('error');
			error = true;
		}
		if ($('#comment-form #comment').val() == '' && $('#comment-form #comment').length) {
			$('#comment-form #comment').addClass('error');
			error = true;
		}
		if (error) {
			//Return false so we don't actually submit the form
			return false;
		}
	});	
	// Remove error css class on focus or click
	$('#comment-form input, #comment-form textarea ').focus(function(){
		$('#comment-form #author').removeClass('error');
		$('#comment-form #email').removeClass('error');
		$('#comment-form #comment').removeClass('error');
	});

	$('#comment-form').blur(function(){
		$('#comment-form #author').removeClass('error');
		$('#comment-form #email').removeClass('error');
		$('#comment-form #comment').removeClass('error');
	});
	
	//Search submit
	$('#searchform').submit(function(){
	
		if ($('#searchform #s').val() == '') {
			$('#searchform #s').addClass('error');
			
			//Return false so we don't actually submit the form
			return false;
		}
	});	
	// Remove error css class on focus or click
	$('#searchform #s').focus(function(){
		$('#searchform #s').removeClass('error');
	});

	$('.newsletter form').blur(function(){
		$('#searchform #s').removeClass('error');
	});
	
	//Newsletter submit
	$('.newsletter form').submit(function(){
		var error = false;
		if(!validate_email($('.col #newsletter_email').val()))
		{
			$('#newsletter_email', $(this)).addClass('error');	
			error = true;
		}
		if (!error) {
			$('.newsletter form').hide();
			$('.newsletter .message').fadeIn("slow").delay(3000);
			$.post('', {newsletter_email: $('#newsletter_email').val(), form_type: $('#form_type').val() });
			$('.newsletter .message').fadeOut("slow");
			$('.newsletter form').delay(4200).fadeIn("slow");
			$('#newsletter_email').val('');
			
		}
		//Return false so we don't actually submit the form
		return false;
	});	
	// Remove error css class on focus or click
		$('.newsletter form input').focus(function(){
			$('#newsletter_email').removeClass('error');
		});

		$('.newsletter form').blur(function(){
			$('#newsletter_email').removeClass('error');
		});
	
	//Contact submit
	var error = false;
	$(function(){
		$('.contact form').submit(function(){
		
			if(!validate_email($('#contact_email').val()))
			{
				$('#contact_email', $(this)).addClass('error');	
				error = true;
			}
			if($('#contact_name').val() == '')
			{
				$('#contact_name', $(this)).addClass('error');
				error = true;
			}
			if($('#contact_message').val() == '')
			{
				$('#contact_message', $(this)).addClass('error');
				error = true;
			}
			if (!error) {
				$('.contact form').hide();
				$('.contact .message').fadeIn("slow").delay(3000);
				$.post('', { contact_email: $('#contact_email').val(), contact_name: $('#contact_name').val(), contact_message: $('#contact_message').val(), form_type: $('#form_type').val() });
				$('.contact .message').fadeOut("slow");
				$('.contact form').delay(4200).fadeIn("slow");
				$('#contact_name').val('');
				$('#contact_email').val('');
				$('#contact_message').val('');
				
			}
			error = false;
			//Return false so we don't actually submit the form
			return false;
		});
		// Remove error css class on focus or click
		$('.contact form input, .contact form textarea').focus(function(){
			$('#contact_name').removeClass('error');
			$('#contact_email').removeClass('error');
			$('#contact_message').removeClass('error');
		});
	
		$('.contact form').blur(function(){
			$('#contact_name').removeClass('error');
			$('#contact_email').removeClass('error');
			$('#contact_message').removeClass('error');
		});
	
	});
