var theURL;
var FilterType = '';
$(function(){
	$('ul.menu  li').hover(function(){
		$(this).find('ul').css('display','block');
	},function(){
		//$(this).find('ul').css('display','none');
	});
	$('ul.menu li ul').hover(function(){
		$(this).css('display','block');		
	},function(){
		$(this).css('display','none');		
	});
	
	//$('div.new_new').colorbox({href:theURL});
	if($(".colorbox").length != 0){
		$(".colorbox").colorbox();
		
		$(document).bind('cbox_closed', function(){
			$('#cboxClose').css('height','0px');
	        $('#cboxClose').css('width','0px');
	        $('#cboxClose').css('left','40px');
	        $('#cboxClose').css('top','40px');
		});
	
		$(document).bind('cbox_complete', function(){
	       $('#cboxClose').css('height','46px');
	       $('#cboxClose').css('width','51px');
	       $('.jscroll').jScrollPane({showArrows:true, scrollbarWidth: 13, arrowSize: 13});
		});
		
	}
	
	
	$('a.ajx').click(function(){
		//prepare
		$('#content').html('<div style="text-align:center;padding:30px;"><img src="images/colorbox/loading.gif" /></div>');
		$.get($(this).attr('href')+ '/'+FilterType,null,function(data){
			$('#content').html(data);
			$(".colorbox").colorbox();
		});
		if($(this).attr('rel') != ''){
			FilterType = $(this).attr('rel');
		}
		
		
		//special cases
		if($(this).parent().hasClass('tarbawy') || $(this).parent().hasClass('da3awy')){
			$(this).parent().parent().parent().parent().find('li.current').removeClass('current');
			$(this).parent().addClass('current');
			$(this).parent().parent().parent().addClass('current');
			
			if($(this).parent().parent().parent().parent().hasClass('menu')){
				$('ul.filter li.current').removeClass('current');
			}
			
		}else{
			//normal case
			$(this).parent().parent().find('li.current').removeClass('current');
			$(this).parent().addClass('current');
			if($(this).parent().parent().hasClass('menu')){
				$('ul.filter li.current').removeClass('current');
			}
		}
		return false;
	});
	
	$('#search_form').submit(function(){
		var skw = $(this).find('input.txt').val();
		$('#content').html('<div style="text-align:center;padding:30px;"><img src="images/colorbox/loading.gif" /></div>');
		$.post(aUrl+'media/search',{kw:skw},function(data){
			$('#content').html(data);
			$('ul li.current').removeClass('current');
			$(".colorbox").colorbox();
		});
		return false;
	});

	quoteScroller();
	
});





function quoteScroller(){
	
	var ns = setInterval("scrollquotes()",5000);	
}
function scrollquotes(){
	//alert('ss');
	var ncur = $('div.quotes_content ul li.current');
	//alert(ncur.length);
	var nnext = ncur.next();
	if(nnext.length == 0){
		nnext = $('div.quotes_content ul li:first');
	}
	ncur.fadeOut('fast',function(){
		ncur.removeClass('current');
		nnext.fadeIn('slow');
		nnext.addClass('current');
	});
	
}

function callColorBox(UrL){
	//theURL = UrL;
	$.fn.colorbox({href:UrL});
}



