(function($){
	$.fn.DS = $.fn.default_sliders = function(pos) 
	{
		$.fn.DS.pos = pos;
       	$.fn.DS.delay = 8000;
		           	
		this.find('div.bullet').each(function(i, rel) 
		{
			rel = jQuery('#home-slide'+(i+1)+'-bullet');
			$('<a href=\'#\' id=\'home-slide'+(i+1)+'-link\' ></a>').css(
			{
				width: (rel.width() - 20), height: rel.height(),	
				position: 'absolute', zIndex: 100000,	display: 'block',
				left: rel.position().left, top: rel.position().top				
			})
			.bind('click', $.fn.DS.click).bind('mouseover', $.fn.DS.mouseover).bind('mouseout', $.fn.DS.mouseout).appendTo($(this).parent())[0].di = i;
		}).eq(0).find('span').css({opacity: 1});
		
		$.fn.DS.current = $('#home-slide1-link')[0];		
		$.fn.DS.TOI=setTimeout($.fn.DS.timeout,$.fn.DS.delay);		
		return this;
	};
	$.fn.DS.mouseover = function(e) 
	{
		if(this == $.fn.DS.current) return false;
		$('#home-slide'+(this.di+1)+'-bullet').stop().animate({
			marginRight : $.fn.DS.pos[this.di][2], marginTop : $.fn.DS.pos[this.di][3]
		}, 100);
	};
	$.fn.DS.mouseout = function(e, force) 
	{
		if(this == $.fn.DS.current && !force) return false;
		$('#home-slide'+(this.di+1)+'-bullet').stop().animate({
			marginRight : $.fn.DS.pos[this.di][0], marginTop : $.fn.DS.pos[this.di][1]
		}, 100);
	};
	$.fn.DS.click = function(e, timed, oldSlide, newSlide) 
	{
		if(this == $.fn.DS.current) return false;
		$.fn.DS.lock = true;			
		
		clearTimeout($.fn.DS.TOI);
		
		oldSlide = $('#home-slide'+($.fn.DS.current.di+1));
		newSlide = $('#home-slide'+(this.di+1));
		otherSlides = $('.bullets .slide').not(oldSlide).not(newSlide);
		otherSlides.css({display:'none', opacity: 0});
		
		$(this).trigger("mouseover");
		$('#home-slide'+($.fn.DS.current.di+1)+'-link').trigger("mouseout", [true]);		
		$('#home-slide'+(this.di+1)+'-bullet').find('span').stop().animate({opacity:1}, 250);
		$('#home-slide'+($.fn.DS.current.di+1)+'-bullet').find('span').stop().animate({
			opacity:0	
		}, 250, timed ? function() {
			oldSlide.stop().animate({opacity:0}, 500, function() { 
				oldSlide.hide(); 
				newSlide.css({opacity:0}).show().stop().animate({opacity:1}, 1000, function() {
					$.fn.DS.lock = false;
					$.fn.DS.TOI=setTimeout($.fn.DS.timeout,$.fn.DS.delay);
				});
			});					
		} : function() {});
		
		if(!timed) {
			oldSlide.css({opacity:0}).hide(); 
			newSlide.css({opacity:1}).show();	
			$.fn.DS.lock = false;
			$.fn.DS.TOI=setTimeout($.fn.DS.timeout,$.fn.DS.delay);
		}
		
		$.fn.DS.current = this;	
		return false;
	};
	$.fn.DS.timeout = function() 
	{
		if($.fn.DS.lock) return false;
		var next = $('#home-slide'+($.fn.DS.current.di+1)+'-link').next();
		if(!next.length) next = $('#home-slide1-link');
		next.trigger("click", [true]);
		$.fn.DS.TOI=setTimeout($.fn.DS.timeout,$.fn.DS.delay);
	};	

	
	$.fn.default_focus = function() {
		this.find('a').bind('mouseover', function() {
			
			$(this).parent().find('> p').hide();
			$($(this).attr('href')).show();	
			
			if( $.browser.msie) {
				$(this).parent().find('a').not(this).find('span').hide();
				$(this).find('span').css({display:'block'});
			}
			else {
				
				
				$(this).parent().find('a').not(this).find('span').stop().animate({opacity:0},250, function() { $(this).hide(); });
				$(this).find('span').css({opacity:0, display:'block'}).stop().animate({opacity:1},250);
			}
			return false;
		}).bind('click', function() { return false; }).eq(0).stop().css({display:'block'});
	}

	$.fn.default_webuzz = function(current) {
		
		current = this.find('.media-content:first');		
		this.find('a:first').bind('click', function() {
			var next = current.hide().next();
			current = next.length ? next : $(this).parent().find('.media-content:first');
			current.show();
		});
	}

	$.fn.default_more = function(current, cursor) {
		cursor = this.find('> p:first');
		this.find('a').bind('click', function(target, self) {
			target = $($(this).attr('href'));
			self = $(this);
			
			$(this).parent().find('> div').not(target).stop().animate({opacity:0},250,function(){
				$(this).hide();
				target.css({opacity:0}).show().stop().animate({opacity:1},450);				
			});
			self.parent().find('a').not(self).removeClass('on');
			self.addClass('on').find('span');			
			return false;
		});
		
		this.find('> a').bind('mouseover', function(e) {
			cursor.stop().animate({ left: $(this).position().left+85 });
		}).bind('mouseout', function(e) {
			cursor.stop().animate({ left: $(this).parent().find('a.on').position().left+85 });
		});
	}
	
	$(function(){
		$(".slides").default_sliders([
			[-20, -45, -17, -15],	
			[-18, -30, -16, -20],		
			[-19, -38, -16, -15],		
			[-14, -32, -16, -18]
		]);		
		$('.details .focus').default_focus();
		$('.details .media').default_webuzz();
		$('.more').default_more();
	})
	
	$('#search_field').bind('click' , function(){	
		$('#searchPrevalue').hide();
	});
	$('#searchPrevalue').bind('click' , function(){	
		$(this).hide();
		$('#search_field').focus();
	});
	
	/*-----------showHide connect Panel homepage--------*/
	function AuthPanelShow(){
		$('.AuthPanel a.showAuthPanel').bind('click', function(event){
			$(this).animate({
				opacity: 0
			}, 300);
			
			$('.slides .slide h2').animate({
				opacity: 0.1
			}, 300);
			
			$('.slides .slide span').animate({
				opacity: 0.1
			}, 300);
			
			$(this).parent().find('#AuthForm').animate({
				opacity: 1,
				height: 180,
			}, 300, function() {
				$(this).animate({
					height: 180
				}, 500);
				$(this).find('#AuthFormContent').animate({
					opacity: 1
				}, 300);
			}).css('z-index','4');
			event.preventDefault();
		});
	};
	AuthPanelShow();
	
	function AuthPanelHide(){
		$('body').click(function() {
			$('.AuthPanel #AuthForm #AuthFormContent').animate({
				opacity: 0,
			},300, function(){
				$(this).parent().animate({
					height: 84,
					opacity: 0
				},300, function(){
					$(this).css('z-index','2');
					$(this).parent().find('a#signUp').animate({
						opacity: 1
					},300);
					$('.slides .slide h2').animate({
						opacity: 1
					}, 300);
					
					$('.slides .slide span').animate({
						opacity: 1
					}, 300);
				});
			})
		});
		$('.AuthPanel').click(function(event){
			event.stopPropagation();
		});
	};
	AuthPanelHide();
	
})(jQuery);


