$(document).ready(function(){

	mainSlide('slider', 0, 1000, 0);


$("#searchFrm .text").focus(function() {
        if ($(this).val() == "Search IET Faraday") {
            $(this).val("");
        }
    });

$(function(){
  $('input[type=text]').focus(function(){
    if (!this.clicked) {
      $(this).attr('value', '');
      this.clicked = true;
    }
  });
});

$(function(){
  $('input[type=password]').focus(function(){
    if (!this.clicked) {
      $(this).attr('value', '');
      this.clicked = true;
    }
  });
});

if ($('.panel .positionRight')) {
    $('.panel .positionRight').parent().css(
    "min-height",
    $('.panel .positionRight').height() - 24,
    "height",
    $('.panel .positionRight').height() - 24
);
}

//Carousel
	$(function() {
		var step = 2; 
		var current = 0; 
		var maximum = $('#carousel ul li').size(); 
		var visible = 2; 
		var speed = 1000; 
		var liSize = 380;
		var carousel_height = 161;
 
		var ulSize = liSize * maximum;   
		var divSize = liSize * visible;  
 
		$('#carousel ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");
 
		$('#carousel').css("width", divSize+"px").css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative"); 
 
		$('.btnnext').click(function() { 
		
			if(current + step < 0 || current + step > maximum - visible) {
				return;
			}
			else {
				current = current + step;
				$('#carousel ul').animate({left: -(liSize * current)}, speed, null);
			}
			return false;
		});
 
		$('.btnprev').click(function() { 
			if(current - step < 0 || current - step > maximum - visible) {return; }
			else {
				current = current - step;
				$('#carousel ul').animate({left: -(liSize * current)}, speed, null);
			}
			return false;
		});
	});


});


/* !MAINSLIDER */
	
	function mainSlide($slider, $cycle, $slide, $startslide){
		$('.'+$slider+'').append('<div class="slideButtons"><a href="#" class="previous">previous</a><a href="#" class="next">next</a></div>');
		
		$('.'+$slider+' ul').wrap('<div class="slides" />');
		$('.'+$slider+' .slides').wrap('<div class="slideHolder" />');
		
		$('.'+$slider+' .slides li:first').before($('.'+$slider+' .slides li:last'));
			
		var $listitems = $('.'+$slider+' li:first').siblings().andSelf();
		var $noofli = $listitems.size();
		var $liwidth = $('.'+$slider+' li:first').outerWidth();
		var $totalwidth = $noofli * $liwidth * (-1);
		var $leftpos = $liwidth * $startslide * (-1) - $liwidth;
		
		slideover($('.'+$slider+' a.next'), 0);
		
		$('.'+$slider+' a.next').click(function() {
			$('.'+$slider+' .slides li:last').after($('.'+$slider+' .slides li:first'));
			$leftpos = $leftpos + $liwidth;
			slideover(this, 0);
			$leftpos = $leftpos - $liwidth;
			if ($slide){
				slideover(this, $slide);
			} else {
				fade(this);
			}
			return false;
		});

		$('.'+$slider+' a.previous').click(function() {
			$('.'+$slider+' .slides li:first').before($('.'+$slider+' .slides li:last'));
			$leftpos = $leftpos - $liwidth;
			slideover(this, 0);
			$leftpos = $leftpos + $liwidth;
			if ($slide){
				slideover(this, $slide);
			} else {
				fade(this);
			}
			return false;
		});

		function fade($control) {
			$toSlide = $('.'+$slider+' div.slides');
			$($toSlide).children('ul').fadeOut('slow',function(){
				$($toSlide).css('left',$leftpos);	
			});
			$($toSlide).children('ul').fadeIn('slow');
		};

		function slideover($control, $speed) {
			$toSlide = $('.'+$slider+' div.slides');
			$($toSlide).animate({left: $leftpos},{queue:true, duration: $speed});	
		};

		function cycle(){
			$('.next').click();
			var timer = setTimeout(cycle, $cycle);
		};

		if ($cycle){
			var timer = setTimeout(cycle, $cycle);
		}
	};
/* !END MAINSLIDER */


function checkLoginForm($uField,$pField,$errorDiv){
	 if ($('#'+$uField+'').val() == "" || $('#'+$pField+'').val() == ""){
	 	$('#'+$errorDiv+'').show();
	 	return false;		 
	 } 
	 return true;
}
