﻿$(document).ready(function(){    
	$('#linkToLogin').attr("href","#");
	/*$('#forgotLogin').click(function(){
		$('#mainLoginForm').hide();
		$('#mainForgottenForm').show();
	});*/
		
	$('#quickLinksBt').click(function(){
		if ($('#quickLinksDropOuter').css("display") == 'block'){
			$('#quickLinksDropOuter').hide();
			$('#quickLinksBt').css("background-position", "0px 0px");
		}else{                           
			$('#quickLinksBt').css("background-position", "0px -25px");
			$('#quickLinksDropOuter').show();
		}
		return false;
	});
	
	/* $('.quickLinksDropOuter').mouseout(function(){
	
		$('.quickLinksDropOuter').hide();
		$('#quickLinksBt').css("background-position", "0px 0px");
	
	return false;
	});*/
	 
	/* original         
	$('#loginPop').click(function(){
	  if ($('.loginPopup').css("display") == 'block'){
		$('#loginPop').css("background-position", "0px 0px");
		$('.loginPopup').hide('slow');
	  }else{   
		$('.loginPopup').show('slow');
		$('#loginPop').css("background-position", "0px -25px");
		
		$('.quickLinksDropOuter').hide();
		$('#quickLinksBt').css("background-position", "0px 0px");
	  }
	  return false;
	});*/

	$('#loginPop').click(function(){
	
	  if ($('.loginPopup').css("display") == 'block'){
		$('#loginPop').css("background-position", "0px 0px");
		$('.loginPopup').hide();
	  }else{   
		$('#loginPop').css("background-position", "0px -25px");
		$('#mainForgottenForm').hide();
		$('#mainLoginForm').fadeIn('fast');
		$('.loginPopup').fadeIn('fast');
	  }
	
	  return false;
	});
	  
	$('#readMoreLink').click(function(){
	
	  if ($('.loginPopup').css("display") == 'block'){
		$('#loginPop').css("background-position", "0px 0px");
		$('.loginPopup').hide();
	  }else{   
                  $(window).scrollTop(0);
                  $('.loginPopup').css("background-color", "#ffeeee");
		$('#loginPop').css("background-position", "0px -25px");
		$('#mainForgottenForm').hide();
		$('#mainLoginForm').fadeIn('fast');
		$('.loginPopup').fadeIn('fast');
	  }
	
	  return false;
	});
	  
	/** feature control **/
	
	$('#homeFeature .galery a').each(function(i){
		// stores the number on the link
		$(this).data("index",i+1);
	});
	
	$('#homeFeature .galery a').click(function(){
		//hide hide the others
		$('#homeFeature .galery .nextThumb').attr("name",$(this).data("index"));
		$('#homeFeature .galery .previousThumb').attr("name",$(this).data("index"));
		$("#homeFeature .featureItem[id!=feature"+ $(this).data("index") +"]").slideUp();
		
		//show the requested one
		$("#homeFeature .featureItem[id=feature"+ $(this).data("index") +"]").slideDown();
		$('.galery img'  ).css("border-color", "#ffffff");
		$('#'+ $(this).data("index") +' img'  ).css("border-color", "#00869c");
		displayThumbnailImage();
		return false;
	});
	$('#homeFeature .galery .previousThumb').click(function(){
		//hide hide the others
		var current =parseInt($(this).attr("name")) ;
		var prevT = current-1;
		
		if(current > 1){
			$("#homeFeature .featureItem[id!=feature"+ prevT +"]").slideUp();
			//show the requested one
			$("#homeFeature .featureItem[id=feature"+ prevT +"]").slideDown();
			$('#homeFeature .galery .nextThumb').attr("name", prevT );
			$('#homeFeature .galery .previousThumb').attr("name", prevT );
			$('.galery img'  ).css("border-color", "#ffffff");
			$('#'+ prevT +' img'  ).css("border-color", "#00869c");
		}	
		displayThumbnailImage();
		return false;
	});
	
	 
	$('#homeFeature .galery .nextThumb').click(function(){
		//hide hide the others
		var current =parseInt($(this).attr("name")) ;
		var nextT = current+1;
		
		if(current < document.getElementsByName('thumbnailImage').length){
			$("#homeFeature .featureItem[id!=feature"+ nextT +"]").slideUp();
			//show the requested one
			$("#homeFeature .featureItem[id=feature"+ nextT +"]").slideDown();
			
			$('#homeFeature .galery .nextThumb').attr("name", nextT );
			$('#homeFeature .galery .previousThumb').attr("name", nextT );
			$('.galery img'  ).css("border-color", "#ffffff");
			$('#'+ nextT +' img'  ).css("border-color", "#00869c");
		}
		displayThumbnailImage();
			
		return false;
	});
	  
	$('.thumbnailImage')
	displayThumbnailImage();
	function displayThumbnailImage(){
		$(".galery a").each(function() {
			var totalNode   = parseInt(document.getElementsByName('thumbnailImage').length);
			var activeNode  = parseInt($('#homeFeature .galery .nextThumb').attr("name"));
			var currentNode = parseInt($(this).attr("id"));
			switch(activeNode){
				case 1 : if(currentNode > activeNode  + 2 ) $(this).css("display" , "none"); else $(this).css("display" , "block");
					break;
				case totalNode : if(currentNode < activeNode - 2 ) $(this).css("display" , "none"); else $(this).css("display" , "block"); 
					break;			
				default: if(currentNode < activeNode  - 1 || currentNode > activeNode  + 1) $(this).css("display" , "none"); else $(this).css("display" , "block");
			}		
		});
	}

function autoFill(id, v){
	$(id).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).val(v);
		}
	});

}

autoFill($("#q"), "Search");

});	
