$(document).ready(function(){
	jQuery.fn.extend({ 
	 fadeInOutHover: function() { 
			return this.fadeTo("slow", .5).css('cursor','pointer').hover(function(){$(this).fadeTo("slow", 1);},function(){$(this).fadeTo("slow", .5);});
	  			},
	  fadeOutInHover: function() { 
			return this.fadeTo("slow", 1).css('cursor','pointer').hover(function(){$(this).fadeTo("slow", .5);},function(){$(this).fadeTo("slow", 1);});
	  			}
	});

});

$(function(){
   commonTask();
	navigation('#category ul li a');
	$('a#watch').click(function(){ 
								$('#fplayer').show('slow').find('span').click(function(){
																					  $('#fplayer').hide('slow');
																					  });
								
								})
});
//image preloader
$(window).bind('load', function() {
	var preloadImages=['fplayer.png','vplayer.jpg','loader.gif'];
    $.each(preloadImages,function(i,s) {
		var img = new Image();
		img.src = 'images/'+s;
    })
});


function valign(outer,inner){
	var IpopTop = (outer.clientHeight - inner.offsetHeight)/2;
	var IpopLeft = (outer.clientWidth - inner.offsetWidth)/2;
	outer.css({position:"relative"});
	inner.css({position:"absolute",top:"50%",left:"50%",margin:(-inner.clientHeight/2)+"px auto auto "+(-inner.offsetWidth/2)+"px"});
}

function navigation(ref){
	
function bg(img,xPos,yPos){
	return img+' -'+xPos+'px '+yPos+' no-repeat';
}
	$(ref).not(':animated').each(function(i,o){
			var ul=$(o).parents('ul');
			var links=ul.find('a');
			var img=ul.css('background-image');
			var width=$(o).width();
			var index=links.index(o);
			var xPos=100*index+6;
			var currentPage=basename(window.location.href.toString());
			if($(o).attr('href')==currentPage || $(o).parent().attr('id')=='current')
			{
				   $(o).css({background:bg(img,xPos,'bottom')});
			}
			else 
			{
				   $(o).hover(function(){
										 $(this).css({background:bg(img,xPos,'bottom')});
										},
							  function(){
										$(this).css({background:bg(img,xPos,'top')});
										 });
			}
	});
}

function filename(ref){
	var LEN=ref.length;
	var len=ref.lastIndexOf('/')+1;
	var bname=ref.substring(len,LEN);
	bname=bname.split(/(#|\?)/)[0];
	return bname;
}

function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');  
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}
function stylizedCurrentLink(ref,index,xPos){
			var links=$(ref).parents('ul').find('a');
			var index=links.index(ref);
			var xPos=100*index;

}

function commonTask(){
	$('input:not(:submit),textarea').each(function(i,o){
							 $(o).focus(function(){if(this.value==this.defaultValue) this.value='';})
								 .blur(function(){this.value=($.trim(this.value)=='')?this.defaultValue:$.trim(this.value);});
								 })
	$('a').focus(function(){$(this).blur()});
	$('a[@href=#]').click(function(){return false;});
	//$('a img').fadeOutInHover();
	//$('span#prev,span#next','#slider').fadeInOutHover();
}