$(document).ready(function(){
//global people						   
	$("#mod12-slide").easySlider({
		auto: true,
		pause: 5000,
		continuous: true 
	});
	
	$('.scroll').click(function(){
		var to = $(this).attr('rel');		
		$.scrollTo(to, 1200);		
		return false;	
	});
	
	$('.back-top a').click(function(){
		var to = $(this).attr('href');		
		$.scrollTo(to, 1200);		
		return false;
	});
	
	$('#slider1').s3Slider({
		timeOut: 5000
	});
	
	$('#slider2').s3Slider({
		timeOut: 5000
	});
	
	$("#mod7-panel").jCarouselLite({  
		vertical: true,  
		visible: 5,  
		auto:3000,  
		speed:1000  
	});  
	
	$("#mod6-panel1").jCarouselLite({  
		vertical: true,  
		visible: 10,  
		auto:2000,  
		speed:1000  
	});  

	$("#mod6-panel2").jCarouselLite({  
		vertical: true,  
		visible: 10,  
		auto:2000,  
		speed:1000  
	});

	$("a[rel='photo-gallery']").colorbox();
	$("a.colorbox").colorbox();
	$(".call-signin").colorbox({inline:false, href:base_url+"member/callsignin"});
	$(".call-request").colorbox({inline:false, href:base_url+"request/callrequest"});
	$(".call-member").colorbox({inline:false});
	$('input[title!=""], textarea[title!=""]').hint();
	$('textarea').elastic();
	
	/* Character Limiter
	var onEditCallback = function(remaining){
		$(this).siblings('.maxlenght-remains').text("Characters remaining: " + remaining);

		if(remaining > 0){
			$(this).css('background-color', 'white');
		}
	}
	var onLimitCallback = function(){
		$(this).css('background-color', 'yellow');
	}
	$('textarea[maxlength]').limitMaxlength({
		onEdit: onEditCallback,
		onLimit: onLimitCallback,
	});*/
	
	$('.stream-audio-low').popupWindow({
		windowURL:base_url+'player/audio',
		windowName:'audio',
		centerScreen:1,
		resizable:0,
		height:240,
		width:324
	});


// tab-content gallery
	$('#mod3-mask').css({'height':$('#mod3-panel1').height()});	
	$('#mod3-panel').width(parseInt($('#mod3-mask').width() * $('#mod3-panel div').length));
	$('#mod3-panel div').width($('#mod3-mask').width());
	
	//Get all the links with rel as panel
	$('a[rel=mod3-panel]').click(function () {
		var panelheight = $($(this).attr('href')).height();
		$('a[rel=mod3-panel]').removeClass('selected');
		$(this).addClass('selected');
		
		$('#mod3-mask').animate({'height':panelheight},{queue:false, duration:500});			
		
		$('#mod3-mask').scrollTo($(this).attr('href'), 800);	
		return false;
	});

//tab-content chart
	$('#mod6-mask').css({'height':$('#mod6-panel1').height()});	
	$('#mod6-panel').width(parseInt($('#mod6-mask').width() * $('#mod6-panel div').length));
	$('#mod6-panel div').width($('#mod6-mask').width());
	
	//Get all the links with rel as panel
	$('a[rel=mod6-panel]').click(function () {
		var panelheight = $($(this).attr('href')).height();
		$('a[rel=mod6-panel]').removeClass('selected');
		$(this).addClass('selected');
		
		$('#mod6-mask').animate({'height':panelheight},{queue:false, duration:500});			
		
		$('#mod6-mask').scrollTo($(this).attr('href'), 800);	
		return false;
	});	
	
//tab
	$("ul.tab-nav a").click(function() {
		var curChildIndex = $(this).parent().prevAll().length + 1;
		$(this).parent().parent().children('.current').removeClass('current');
		$(this).parent().addClass('current');
		$(this).parent().parent().next('.tab-container').children('.current').slideUp('slow',function() {
		$(this).removeClass('current');
		$(this).parent().children('div:nth-child('+curChildIndex+')').slideDown('slow',function() {
		$(this).addClass('current');
		});
	});
	return false;								
	});	
	
	/*
	//SHOUT
	timestamp = 0;
	updateMessage();
	$("#form-shout .loader").hide();
	$("#form-shout #submit-shout").click(function(){
		if($("#input-shout").val()!="Shout..." || $("#input-shout").val()!=""){
			$("#form-shout .loader").show();
			$("#form-shout .bt-comment").hide();
			$.post(base_url+"shout/backend",{
						message: $("#input-shout").val(),
						action: "postmsg",
						time: timestamp
				},
				function(xml) {
					$("#shout-list li:last").slideDown("slow",
					function() {
						addMessages(xml);
						$('#input-shout').val('');
						if($("#shout-list li").length > 10)
						{
							$("#shout-list li:first").slideUp("slow", 
							function() {							
								$(this).remove();
							});
						}
					});
					$("#form-shout .loader").hide();
					$("#form-shout .bt-comment").show();
				}
			);		
		};
		return false;
	});
	*/
	
	$(".notification").hide().delay(2000).fadeIn(1000).delay(4000).fadeOut(1000);
	
	//banners
	$('#banner-slides').cycle({
		 fx:     'blindY,blindX,blindZ,cover,fade,fadeZoom,growX,growY,scrollDown,scrollLeft,turnUp,turnDown,turnLeft,turnRight,uncover,wipe,zoom,scrollRight,scrollUp',
		 randomizeEffects: true, 
		 speed:   1000,
		 timeout: 6000,
		 delay:  -2000,
		 pause: 1
	});
	
	// New Rotate
	
	$('#sliderContent').cycle({
		 fx:     'fade',
		 speed:   1000,
		 timeout: 6000,
		 delay:  -2000,
		 pause: 1,
		 before: onBefore
	});
	
	$('#sliderContent2').cycle({
		 fx:     'fade',
		 speed:   1000,
		 timeout: 6000,
		 delay:  -2000,
		 pause: 1,
		 before: onBefore
	});
	
	function onBefore() {
		var $ht = $(this).height();
		$(this).parent().animate({height: $ht});
	}
	
	// Tips
	$("#btn-contact-footer").click(function(){
		if(($("#contact-footer-email").val()!='email...') && ($("#contact-footer-message").val()!='write your message...')){
			return true;
		}else{
			return false;
		}
	});
	
	//sitemap
	$("#navigation").treeview({
		animated: "fast",
		persist: "location",
		collapsed: true,
		unique: true
	});	

});

// Shout 
	function addMessages(xml) {
		if($("status",xml).text() == "2") return;
		timestamp = $("time",xml).text();
		$("message",xml).each(function(id) {
			message = $("message",xml).get(id);
			$("#shout ul").append("<li><p><span>"+$("member_fullname",message).text()+" :</span>"+$("text",message).text()+"</p></li>");
			if($("#shout-list li").length > 5)
				{
					$("#shout-list li:first").slideUp("slow", 
					function() {							
						$(this).remove();
					});
				}
			});
	}
	function updateMessage() {
		$.post(base_url+"shout/backend",{ time: timestamp }, function(xml) {
			$("#loading").remove();				
			addMessages(xml);
		});
		setTimeout('updateMessage()', 4000);
	}

