var $ = jQuery.noConflict();

jQuery(document).ready(function($){

	JQTWEET.loadTweets();

	if($('#menu-sidebar-navigation')){
		$('#menu-sidebar-navigation a').each(function(i){			
			if ( $(this).attr('href') == document.location.href ) {$(this).addClass('active');}		
		});
	}


	if($("#excerpt-home").length > 0){
		$("#excerpt-home").ScrollNews({
		   inizialize  : 'true',
		   size        : '162px',
		   timeout     :  2500,
		   speed       :  'fast',
		   direction   : 'down',
		   onmouseover : 'stop'
		});
	}

	$('.sshow').fadeIn(1200);
	
	if( $('.sshow').length){
			
		$('.sshow').cycle({ 
			fx:     'fade', 
			speed:  1200, 
			delay: 1000,
			timeout: 4000,
			next: '.sshow'
		});
	
	}
	
	$('#dtxtquotes').fadeIn(1200);
	$('#dtxtquotes').cycle({ 
			fx:     'fade', 
			speed:  1200,  
			delay: 1200,
			timeout: 6000,
			next: '#dtxtquotes',
			random: 1
	});
	
	
	$('.contact, .questions').hover(
		function(){$(this).find('em').stop().fadeTo(50, 1);}, 
		function(){$(this).find('em').stop().fadeTo(500, 0);}
	);

	$('.contact').prepend('<em></em>');	
	$('.questions').prepend('<i><strong></strong></i><em></em>');		
	
	$('.questions').hover(
		function(){$(this).find('i strong').stop().fadeTo(50, 1);}, 
		function(){$(this).find('i strong').stop().fadeTo(500, 0);}
	);


	$('#header .navigation a').append('<span><b>ogk</b></span>');
	$('#header .navigation a').hover(
		function(){
			$(this).find('span').stop().fadeTo(50, 1);
		}, 
		function(){
			$(this).find('span').stop().fadeTo(500, 0);
	});

	$("#footer-form").validate();
	$("#news-submit").validate();

	var validate = function(){
		if( $('#fname').val() == 'First Name' || $.trim( $('#fname').val() ) == '' ){
			$('#fname').addClass('error');
		}
		if( $('#email').val() == 'Email' || $.trim( $('#email').val() ) == '' ){
			$('#email').addClass('error');
		}
		if( $('#phone').val() == 'Phone' || $.trim( $('#phone').val() ) == '' ){
			$('#phone').addClass('error');
		}
		if( $('#message').val() == 'Message' || $.trim( $('#message').val() ) == '' ){
			$('#message').addClass('error');
		}
	};

	/*var validate = function(){
		if( $('#fname').val() == 'First Name' || $.trim( $('#fname').val() ) == '' ){
			$('#fname').val('');
		}
		if( $('#email').val() == 'Email' || $.trim( $('#email').val() ) == '' ){
			$('#email').val('');
		}
		if( $('#phone').val() == 'Phone' || $.trim( $('#phone').val() ) == '' ){
			$('#phone').val('');
		}
		if( $('#message').val() == 'Message' || $.trim( $('#message').val() ) == '' ){
			$('#message').val('');
		}
	};*/

	$("ul#menu-sidebar-navigation a[href=" + location + "]").addClass('active');

	// Contact Form Footer Ajax

	$('button.contact-btn').click(function(){
		form = $("#footer-form");
		validate();$("#footer-form").validate();
		if(form.find('input.error').length > 0) return false;
		send = form.serialize() + "&type=ajax&submit=Send";
		$.post( '/contact-us', send, function(data){
			if(data['status'] == 'failure'){
				$('div.failure').fadeIn().text(data['msg']);
				form.hide();
			}
			else if(data['status'] == 'success'){
				$('div.success').fadeIn().text(data['msg']);
				form.hide();
			}

			// alert(data['msg']);
		}, "json");

		return false;
	});

	// Newsletter Form Footer Ajax

	$('button.newsletter').click(function(){
		if( !$('#news-submit').valid() ){
			$('#ne').addClass('error');
			return false;
		}
		form = $('#news-submit');
		send = form.serialize();

		$.post( '/newsletter', send, function(data){
			// alert(data);
			if(data.indexOf('Follow the link in it to confirm the subscription') != -1){
				$('div.nsuccess').fadeIn().text("You have been subscribed successfully!");
				form.hide();
			}
			else{
				$('div.nsuccess').fadeIn().text("Invalid email address, please check your email and try again.");
				form.hide();
			}
		});
		return false;
	});
	
	tooltip();
	screenshotPreview();


	$("ul#menu-sidebar-navigation a[href=" + window.location + "]").addClass('active'); 
	$('.blank').click(function(){ window.open(this.href);return false });

});
 
