$(document).ready(function(){

	//****SEARCH HOVER STARTS HERE*****//
	
	//Start Search Text
	var StartSearchText = $(".search-input").val();
	
	//Detect the click on the search icon and open the search form
	$(".search a").click(function(){
	
		$(".search-popup").fadeIn("slow");
		$(".search-input").fadeIn("slow");
		
		return false;
	
	});
	
	//Detect the click on the input and just do nothing
	$(".search-input").click(function(){
	
		return false;
		
	});
	
	//Detect a click outside the input and close the form
	$(document).bind("click", function() {
		
		$(".search-popup").fadeOut("slow");
		$(".search-input").fadeOut("slow");
	
	});
	
	//Detects the focus on the text field
	$(".search-input").focus(function(){
	
		if( $(this).val() == StartSearchText ){
			$(this).val('');
		}
	
	});
	
	//Detects the blur on the text field
	$(".search-input").blur(function(){
	
		if( $(this).val() == '' ){
			$(this).val(StartSearchText);
		}
	
	});
	
	//****SEARCH HOVER ENDS HERE*****//
	
	
	//Get Twitter Feed
	
	$.jTwitter('eleftheriagr', 1, function(posts){
  		
  		for(var i=0; i<posts.length; i++){
     		$('.twitterfeed p').html(posts[i].text);
     		
     		$.linkify($('.twitterfeed p'));
  		}
  		
	});
	
	//Images Hover Effect
	
	$(".content img:not(.nohover)").hover(   /***** CHANGED THIS TO SELECT IMAGES THAT DON'T HAVE CLASS="NOHOVER" *****/
		function(){
			$(this).fadeTo(300, 0.6);
		}, 
	
		function(){
			$(this).fadeTo(300, 1);
		}
	);
	
	
	//contact form
	$("#contactForm").submit(function(){
	
		$("#pleasewait").fadeIn("slow");
		
		$.ajax({
 	
 			url: $("#contactForm").attr("action"),
  			data: $("#contactForm").serialize(),
  			dataType: 'json',
  			type: "POST",
  			success: function(data){
  			
  				if( data.status ){
  				
					$("#contact-message-wrapper").fadeOut("slow", function(){
						$("#contact-message-wrapper").html('');
						$("#contact-message-wrapper").append('<ul class="contact-success"><li>Το μήνυμα σας στάλθηκε επιτυχώς!</li></ul>');
						$("#contact-message-wrapper").fadeIn("slow");
						
						$("#name").val('');
						$("#subj").val('');
						$("#email").val('');
						$("#message").val('');
					});
  				
  				}else{
  				
  					$("#contact-message-wrapper").html('');
  					$("#contact-message-wrapper").append('<ul class="contact-errors"></ul>');
  					
  					$.each(data.errors, function(index, value) {
  						$("#contact-message-wrapper > ul").append("<li>"+value+"</li>");
  					});
  					
  					$("#contact-message-wrapper").fadeIn("slow");
  				
  				}
  				
  				$("#pleasewait").fadeOut("slow")
  				  	
  			},
  			error: function(jqXHR, textStatus, errorThrown){
  			
  				alert(errorThrown);
  				$("#pleasewait").fadeOut("slow");
  			
  			}
	
		});
		
		return false;

	});
	
	//subscription form
	$("#subscribeForm").submit(function(){
	
		$("#pleasewait").fadeIn("slow");
		
		$.ajax({
 	
 			url: $("#subscribeForm").attr("action"),
  			data: $("#subscribeForm").serialize(),
  			dataType: 'json',
  			type: "POST",
  			success: function(data){
  			
  				if( data.status ){
  				
					$("#contact-message-wrapper").fadeOut("slow", function(){
						$("#contact-message-wrapper").html('');
						$("#contact-message-wrapper").append('<ul class="contact-success"><li>Η εγγραφή σας ολοκληρώθηκε επιτυχώς!</li></ul>');
						$("#contact-message-wrapper").fadeIn("slow");
						
						$("#fname").val('');
						$("#lname").val('');
						$("#email").val('');
						$("#exists").val('');
						
						location.href = 'subscription_success.asp';
					});
  				
  				}else{
  				
  					$("#contact-message-wrapper").html('');
  					$("#contact-message-wrapper").append('<ul class="contact-errors"></ul>');
  					
  					$.each(data.errors, function(index, value) {
  						$("#contact-message-wrapper > ul").append("<li>"+value+"</li>");
  					});
  					
  					$("#contact-message-wrapper").fadeIn("slow");
  				
  				}
  				
  				$("#pleasewait").fadeOut("slow")
  				  	
  			},
  			error: function(jqXHR, textStatus, errorThrown){
  			
  				alert(errorThrown);
  				$("#pleasewait").fadeOut("slow");
  			
  			}
	
		});
		
		return false;

	});
	
	//Fix the PNG issues in IE6
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {

		$('.footer-left').supersleight({shim: './images/blank.gif'});
		$('.footer-right').supersleight({shim: './images/blank.gif'});
		$('.footer-inner').supersleight({shim: './images/blank.gif'});
		$('.logo').supersleight({shim: './images/blank.gif'});
		$('.nav-wrapper').supersleight({shim: './images/blank.gif'});
		$('.weather-icon img').supersleight({shim: './images/blank.gif'});
		$('.top-weather').supersleight({shim: './images/blank.gif'});
		$('.weather-more').supersleight({shim: './images/blank.gif'});
		$('.weather-declaimer').supersleight({shim: './images/blank.gif'});

	}
	
});
