// JavaScript Document

function navi_mouseover() {	
	$('ul.sub_nav li').hover(
		function() {
			$(this).css("background-color", "rgba(255,255,255,0.25)")
			.css('border-radius','5px')
			.css('-moz-border-radius','5px')
			.css('-khtml-border-radius','5px')
			.css('-webkit-border-radius', '5px');
		},
    	function() {
			$(this).css("background-color", "transparent"); // .parent().css(.animate({opacity:0});
    	}
	);
	//$('ul.sub_nav li').click(
	//	function() { $(this).children().click();  }
	//);	
}


function lookup() {


	var search_str = $('#search_text').val();

		if(search_str.length == 0) {
			$('#suggestions').hide(); // Hide the suggestions box
		}
		else if (search_str.length >= 3) {
			$.post("no_cache/rpc_suche", {queryString: search_str}, function(data) { // Do an AJAX call
				
				$('#suggestions').html(data).show(); // Fill the suggestions box
				// navi_mouseover();		   
		   
			});
		}
}

$(function() {
  var timer;
  $("#search_text").keyup(function() {
	clearTimeout(timer);
	var ms = 250; // milliseconds
    var val = this.value;
    timer = setTimeout(function() {
    lookup();
    }, ms);
  });
});



$(document).ready(function () {

	var animationSpeed = 100;
	var timeStamp = new Date().getTime();
	
	$('#search_text_disbled').keyup(function(event) { 

		if (event.keyCode == '13') {
			event.preventDefault();
		}
		
		if(globalTimeout != null) {
			clearTimeout(globalTimeout); 
		}
 		setTimeout('lookup()',500);  
	});
	
	$(".sub_nav").hide();
	$('#suggestions').hide();
	

	var animationSpeed = 50;
	
	$("ul#navigation li.elem.anim").hover(
		function() {
			$(this).find('.sub_nav').stop(true,true).slideToggle(animationSpeed, 'easeOutQuad', function () {});
    	},
    	function() {
			$(this).find('.sub_nav').stop(true,true).slideToggle(animationSpeed, 'easeInQuad', function () {});
    	}
	);
	
	// navi_mouseover();
	
	animationSpeed = 125;
	$('#search').hover(
		function() {
			$('#search_text').focus();
			$(this).find('#search_text').animate({ width: '93px' }, animationSpeed);
			$(this).animate({ width: '113px' }, animationSpeed);
			$('ul#navigation > li.anim').animate({ width: '68px' }, animationSpeed);
		},
    	function() {
			$(this).find('#search_text').animate({ width: '30px' }, animationSpeed);
			$(this).animate({ width: '50px' }, animationSpeed);
  			$('ul#navigation > li.anim').animate({ width: '75px' }, animationSpeed);
	});
	
	
	// display the shop cart via js sice it's all cached
	$.get('no_cache/cart_count/' + timeStamp + "/" + Math.floor(Math.random() * 9999), function(data) {
		if (parseInt(data) > 0) {
			$('.cart').addClass('active');
			$('#shop_count').html("(" + data + ")");
		}
	});
	
	// update the counter since it's cached
 	setInterval(function() {
		$.ajax({
			url: "no_cache/count_views/" + timeStamp + "/" + Math.floor(Math.random() * 9999),
			success: function(response){
				$(".count_views").html(response);
			}, dataType: "html"}) }
	, 120000);

	// news scroller
	$('div#last_events, div#best_pics, div#main_content').jScrollPane();
	
	$('.wrap').hover(function(){
		var comm_height;
		comm_height = 120 - $(this).children('.comment').outerHeight();
		
  		$(this).children('.comment').stop().animate({'top': comm_height + 'px'}, 150);}
	, function(){  
  		$(this).children('.comment').stop().animate({"top": '120px'}, 150);});
	
	// $(".column").equalHeights(400, 800);//  Sets all cols to at least 400px tall.
	$(".column").equalHeights(600,800);
  
});

$(".column").resize(function(){
 	$(".column").equalHeights(600,800);
});

