/* Name: detikSlider
 * Version: 1.0
 * Last Update: 16.06.2009
 * Updated by : Didik Wicaksono
 * Created by : Didik Wicaksono
 * NOTE : Erase all comments and compress this script while in use
 * */

jQuery(function($){
    /* general options, Edit information below this area: */
        $slides = 4; // Number of slides to be displayed in the slideshow
        $margin = 0; // Distance between slides
        $nav = $('#detikhighlightnav a'); // The Anchor for Slide navigation, e.g $('#divIDnav a')
        $div = $('#detikhighlightwrapper ul li'); // List of slides , e.g: $('#divIDwrapper ul li')
        $delay = 3000; // Time delay, in miliseconds;
        $delayaft = 10000; // Time delay after clicking navigation, in miliseconds. Set '0' to disable animation
	$('#detikhighlight').show(); // Custom detikForum
    /* All Done! Don't edit below this */
        $divwidth = parseInt($div.css("width")) + $margin ; // Calculate slideshow container's width
        $divheight = parseInt($div.css("height")) + $margin; // Calculate slideshow container's height
        $alldiv = $div.length; // Count the number of slides
        $div.parent('ul').css({"width": $alldiv*$divwidth,"height": $divheight }).parent('div').css({"height": $divheight}) // Rewrite the slideshow container's dimension
        $div.each(function(index){
           $(this).css({"left" : index*$divwidth })
        }); // Make all slides distance each other
        if($alldiv<=$slides){$nav.parent('div').hide()}; // Hide navigation if insufficient slides
        /* Begin The Show */
            var i=0; //Index of slide
            var simpleslide = function simpleslide() {
                if(i==($alldiv-$slides) || 0>($alldiv-$slides) ){
                    i = 0; // end of slide
                } else {
                    i = ++i % $alldiv;
                }
                console.log(i);
                $div.parent('ul').animate({"left": i*(-1)*($divwidth)})
                timeoutslide = setTimeout(simpleslide,$delay);
            };
         /* Navigation */
            $nav.filter('.next').click(function(){
               clearTimeout(timeoutslide);
               if(i==($alldiv-$slides)){
                    i = 0; // end of slide
                } else {
                    i = ++i % $alldiv;
                }
                $div.parent('ul').animate({"left": i*(-1)*($divwidth)})
                if($delayaft!=0){timeoutslide = setTimeout(simpleslide,$delayaft);}
               return false;
            });
            $nav.filter('.previous').click(function(){
               clearTimeout(timeoutslide);
               if(i==0){
                    i = ($alldiv-$slides); // end of slide
                } else {
                    i = --i % $alldiv;
                }
                $div.parent('ul').animate({"left": i*(-1)*($divwidth)})
                if($delayaft!=0){timeoutslide = setTimeout(simpleslide,$delayaft);}
                return false;
            });
         /* Hovering */
             $div.hover(function(){
                 clearTimeout(timeoutslide);
				 $('#detikhighlightnav').show();
             },function(){
                 clearTimeout(timeoutslide);
				 if($delayaft!=0){timeoutslide = setTimeout(simpleslide,$delayaft);}
             });
    timeoutslide = setTimeout(simpleslide,$delay);// initialize!
	
	// detikSearch!
	$('.pencarian .cari02 input').focus(function(){
		$(this).css({'background-position':'0 -100px'})
	}).blur(function(){$(this).css({'background-position':'0 50%'})});
});