function onBefore() { 
	$('#output').html("Scrolling image:<br>" + this.src); 
} 
function onAfter() { 
	$('#output').html("Scroll complete for:<br>" + this.src) 
		.append('<h3>' + this.alt + '</h3>'); 
}

(function($) {
    $.fn.simpleTab = function(options){
        options = options || {};
        return this.each(function(){
            var self = this,
            localOptions = $.extend({selectedClass: "tab-current"}, options);
            
            $(this).addClass('tabs-wrapper');
            $('div.tabbed-body div', this).hide();
            $('div.tabbed-body div:first', this).show();
            $('div.tabbed-head div.navigation a:first', this).addClass(localOptions.selectedClass);
            
            $('div.tabbed-head div.navigation a', this).click(function(){
                var href = $(this).attr('href');
                $('div.tabbed-body div', self).hide();
                $('div.tabbed-body div' + href, self).show();
                $('div.tabbed-head div.navigation', self).removeClass(localOptions.selectedClass);
                $(this).parent().addClass(localOptions.selectedClass);
                return false;
            });
        });
    };
	
    $.fn.newsTicker = function(options){
        options = options || {};
        return this.each(function(){
            var $strip = $(this),
            localOptions = $.extend({duration: 3000, axis: "x", easing: "linear"}, options),
            margin = $strip.children().width(),
            duration = 0,
            curtime = 0,
            difftime = 0,
            ulWidth = 0,
            tmpWidth = 0,
            n = 0;
            
            $strip.find("li").eq(0).before("<li>&nbsp;</li>");
            $strip.find("li").each(function(i){                
                tmpWidth = $(this, i).width();
                ulWidth += tmpWidth + margin;
                
                $(this,i).css("margin-right", margin);
                n++;
            });
            $strip.find("li").eq(n-2).css("margin-right", 0);
            $strip.find("li").eq(n-1).css("margin-right", 0);
            
            $("ul", this).css("width", ulWidth);
            
            function animateIt(data){
                var curdate = new Date();
                curtime = curdate.getTime();
                
                if (data == null) {
                    duration = localOptions.duration;
                } else {
                    duration = data;
                }
                
                $strip.children().scrollTo('li:eq(' + (n-1) + ')', duration , {
                    easing: localOptions.easing,
                    axis: localOptions.axis,
                    onAfter:
                        function(){
                            $strip.children().scrollTo('li:eq(0)', 1);
                            animateIt();
                        }
                });
            };
            animateIt();
            
            $strip.children().hover(
                function(){
                    var newdate = new Date();
                    difftime = newdate.getTime() - curtime
                    $strip.children().stop();
                },
                function(){
                    animateIt(duration - difftime);
                }
            );
        });
    };	
	
})(jQuery);

$(function() {
	$('a=[rel="external"]').click(function() {
		window.open($(this).attr('href'));
		return false;
	});	
	$('#news_wrapper').simpleTab();
	$('#gallery_wrapper').simpleTab();
 	$('#itemmall').innerfade({
		speed: 'slow',
		timeout: 5000,
		type: 'sequence'
	});
	$(".tips").tooltip();
	$(".newsticker").newsTicker({duration: 90000});
});


$(document).ready(function(){
    $('#banner-slide').cycle({
		fx:     'fade', 
		timeout: 5000, 
		pager:  '#navigation',
		before:  onBefore, 
		after:   onAfter
	});	
});

$(window).load(function(){
	//menuSlider.init('main_menu','slide');
	setTimeout(function() {
		$('#b_body').css({'background': 'transparent url(/img/layout/banner_atas.jpg) no-repeat 18px 80px'});
	}, 1000);
	setTimeout(function() {
		$('body').css({'background': 'url(/img/layout/bg.jpg) repeat'});
	}, 1000);
});
