/*	
	Platino Template
	File: global.js
	Stefano Giliberti - kompulsive@gmail.com clickswitch.net		
*/

$(document).ready(function(){
	/*** Search label  ***/
	htmlinput = $("input#panel-search").val() /* picks the inital value of the input (in the html) */
	$("input#panel-search").css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
	$("input#panel-search").focus(function(){ /* on focus.. */
		curinput = $(this).val() /* picks the -current- value */
		if(curinput == htmlinput){ /* if the current value corrispond to the initial value (htmlinput var) */
			$(this).val(''); /* empty the input */
			$(this).css('color','black').css('font-style', 'normal').css('font-weight','normal');
		}
	});
	$("input#panel-search").blur(function(){ /* on blur */
		curinput = $(this).val();
		if(curinput == ''){ /* if the current value is null .. */
			$(this).css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
			$(this).val(htmlinput); /* sets the value with its inital value (htmlinput var) */
		}
	})    

	/* Main Navigation hover effect */
	$("ul#navigation li:not('.current'), ul#navigation li:not('highlighted')").hover(
      function () {
        $(this).addClass("hover");
      }, 
      function () {
        $(this).removeClass("hover");
      }
    );

	/* Right Menu hover effect */
	$("ul#fast-links li:not('.current')").hover(
      function () {
        $(this).addClass("current");
      }, 
      function () {
        $(this).removeClass("current");
      }
    );
	
	/*** Contact form validation  ***/
	/* On focus change input and textarea color */
    $("#contact-form input, #contact-form textarea").focus(function () {
		/* Style */
        $(this).css("background","#FDFFCA");
        $(this).css("border-color","#DBDF6F");
    });

	/* On blur */
    $("#contact-form input, #contact-form textarea").blur(function () {
		var inputVal = jQuery.trim($(this).val()); /* Grabs actual input value and removes white space before and after it! */
		$(this).val(inputVal); /* Re-add the input without spaces */
		
		/* Style */
		$(this).css("background","white");
        $(this).css("border-color","#b7ddf2");
		
		var checkReq = $(this).attr("title"); /* Grabs input title="" */
		if (checkReq == "required" && inputVal == "") { /* If the title correspond to "required" AND the input is blank */
			$(this).css("background","#ffc9c9");
        	$(this).css("border-color","#ff4f4f");
    	} else {
    		$(this).css('background','#C9FFD0'); 
			$(this).css("border-color","#4FFF56");
		}
	});

	/*** Alternates row colors! ***/
	$("tr:odd").css("background-color", "#f3f3f3");
	
	/*** Homepage Slider ***/
	if($("#slider li").size() > 1) { /* If <li> items are more than 1, starts everything! */

		$("#slider").easySlider({
			/* 
				http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding 
			*/
			speed: 600, /* Sliding speed */
			auto: true, /* Auto slide */
			pause: 6000,
			vertical: true, 
			continuous: true,
			prevId: 'prev-slide', /* Previous control button ID */
			nextId: 'next-slide' /* Next control button ID */
		});
					
		/* Sets controls opacity to 0.2 by default */
		$("#prev-slide, #next-slide").css("opacity", 0.2);
		
		/* Controls - On hover */
		$("#prev-slide, #next-slide ").hover(
		  function () { 
			$(this).animate({ opacity: 1 }, { duration: 200 }); /* On hover, Show it completely */
		  }, 
		  function () {
			$(this).animate({ opacity: 0.2 }, { duration: 200 }); /* When mouse leave, resets the opacity to 0.2 */
		  }
		).click(
		  function () { 
			$(this).fadeOut(200).fadeIn(400); /* On click blinks the button */
		});

	}
	
});