$(function() {
        // Page load
        $(".nav ul li a").css("opacity","1");
        // Mouse over
        $(".nav ul li a").hover(function () {
            $(this).stop().animate({
                opacity: 1
            }, "slow");
        },
        // Mouse out
        function () {
            $(this).stop().animate({
                opacity: 1
            }, "slow");
        });
    });

jQuery.widget("ui.carousel", {
	options : {
		data: []
		,stop:false
	},
	_create : function() {
		var _self_c = this;
		this.current = 0;
		this.timer =  setInterval(function(){
			_self_c.next()
		},5000);
		
		this.element.find('.right-arrow').click(function(){			
			_self_c.next();
		})
		
		this.element.find('.left-arrow').click(function(){
			
			_self_c.prev();
		})
		this.element.mouseover(function(){
			clearTimeout(_self_c.timer); 
		}).mouseout(function(){
			_self_c.timer =  setInterval(function(){
				_self_c.next()
			},5000);		
		})
	},
	next:function(){		
		this.current++;
		if(this.current == this.options.data.length){
			this.current = 0;
		}
		this.goTo();
	},
	prev:function(){
		if(this.current == 0){
			this.current = this.options.data.length-1;
		}else{
			this.current--;
		}
		this.goTo();
	},
	goTo:function(){
		var _self_c = this;
		this.closeDescription(function(){
			 var newobj = _self_c.options.data[_self_c.current]
            _self_c.element.find('.description .title')
            	.html(newobj.title)
            	.attr('title',newobj.title);
	        _self_c.element.find('.description .text')
            	.html(newobj.text)
	        _self_c.element.find('.description .goto')
            	.attr('href',newobj.href)
			_self_c.element.find('.description .title')
            	.attr('href',newobj.href)				
            _self_c.openDescription();
		})
		this.element.find('.image').animate({
		    opacity: 0,
		    "left": "+=400px"
		  }, 1000,function(){
			jQuery(this).find('img')
				.attr('src',_self_c.options.data[_self_c.current].src)
				.attr('alt',_self_c.options.data[_self_c.current].title)
			_self_c.element.find('.image').animate({
			    opacity: 1,
			    "left": "-=400px"
			  }, 1000 );
		});
	},
	closeDescription:function(callback){
		this.element.find('.description').animate({
		    opacity: 'toggle',
		    height: 'toggle'
		  }, 500, function() {			  
			  callback();
		  });
	},
	openDescription:function(){
		this.element.find('.description').animate({
		    opacity: 'toggle',
		    height: 'toggle'
		  }, 500, function() {			  
			 
		  });
	},
	setCurrent:function(idx){
		if(this.current == idx){
			return false;
		}
		this.current =  idx;
		this.goTo();
	}
});

