//open banners in new window
$(document).ready(function(){  
$('.bannerNewWindow').click(function(){
	window.open(this.href);
	return false;
});

$('.clientDesc').hide();

//open link in new window
$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
		$(this).attr('target','_blank');
	});
	
});

$(document).ready(function(){

$(".clientsItem").hover(function(){
               
	                var item = $(this);
	                var f = function(){ showDesc(item); };
	                this.tid = setTimeout(f,600);
	       
        },function(){
	       
	                clearTimeout(this.tid);
                        $(this).find(".clientDesc").slideUp('medium');
	               
	        }); 
	
});

var showDesc = function(item){
	       
   item.find(".clientDesc").slideDown('medium');     
}

//Clear input on click
$(document).ready(function() {
	$('.clear_field').click(function() {
	var orig_value = $(this).val();
	$(this).val("");
	$(this).blur(function () {
	     if ($(this).val()==""){
         $(this).val(orig_value);
		 }
    });
	});
});

//frontpage slideshow
$(document).ready(function() {

	if ($('#slides').attr('id')){

		var SlideInerval = 10000;
	
		var timeOutId = setTimeout(slideLoader,'500');
		loadImage(timeOutId);
	
		var inreval = setInterval(slideShow,SlideInerval);
	
	}
	
	//new slide
	$('#slideMenu a').click(function(){
	
		inreval = clearInterval(inreval);
		
		$('#slideMenu a').removeClass('active_slide');
		$(this).addClass('active_slide');
	
		loadSlide($(this).attr('href'));
		
		inreval = setInterval(slideShow,SlideInerval);
		return false;
	
	});
	
});

var slideShow = function(){
	
	var nextSlide = $('.active_slide').parent().next().find('a');
	if(!nextSlide.attr('href')) nextSlide = $('#slideMenu li').eq('0').find('a');
	
	$('#slideMenu a').removeClass('active_slide');
	nextSlide.addClass('active_slide');
	
	var nextLink = nextSlide.attr('href');
	
	loadSlide(nextLink);
	}

var slideLoader = function(){

	$('#slide_loading').remove();
	$('#slides').append("<div id='slide_loading'></div>");
}

var loadSlide = function(myurl){

		var slideLink = myurl.split("/")[4]; //NB! url index
		var pirn_url = $("#pirn_url").val();
	
		$('#slide').fadeOut('slow',function(){
		
			var timeOutId = setTimeout(slideLoader,'500');

			$.ajax({
			type: "GET",
			url: pirn_url+"/core/components/slides.inc.php?slide="+slideLink,
			success: function(content){
			
				$('#slide').html(content);
				
				loadImage(timeOutId);
			}
		});
		});

}
	
var loadImage = function(timeOutId){

	var imgsrc = $('#slide').find('img').attr('src');

	var img = new Image();
	
	$(img).load(function(){
		
		clearTimeout(timeOutId);
		$('#slide_loading').fadeOut('slow',function(){ $(this).remove(); });
		$('#slide').fadeIn('slow');
	
	});
	
		img.src = imgsrc;
}