
/*---------------------*/
/*-- FUNCTION CUSTOM --*/
/*---------------------*/

(function($) {
	
	/*-- FUNCTION CUSTOM FADE IN --*/
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
		return $(this);
	};
	
	/*-- FUNCTION CUSTOM FADE OUT --*/
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
		return $(this);
	};
	
	/*-- FUNCTION CUSTOM FADE TO --*/
	$.fn.customFadeTo = function(speed,value, callback) {
		$(this).fadeTo(speed, value, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
		return $(this);
	};
	

	
	/*-- FUNCTION CUSTOM EXPAND AND FADE IN --*/
	$.fn.expandFadeIn = function(speed, callback) {
		$(this).children().fadeTo(0,0);
		$(this).slideDown('fast').fadeTo(speed,1.0, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
		});
		$(this).children().fadeTo(0,1,function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
		return $(this);
	};
	
	/*-- FUNCTION CUSTOM COLLAPSE AND FADE OUT --*/
	$.fn.collapseFadeOut = function(speed, callback) {
		$(this).children().fadeTo('fast',0);
		$(this).fadeTo('slow',function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
		}).slideUp('fast', callback);
		return $(this);
	};
	
	/*-- FUNCTION CUSTOM EXPAND AND FADE IN --*/
	$.fn.expandContract = function(action,callback) {
		if(action == 'expand') {
			if(($(this).html() == '+ 顯示')||($(this).html() == '- 隱藏')) {
				$(this).html('+ 顯示');
			} else {
				$(this).html('+ expand');
			}
		} else if (action == 'contract'){
			if(($(this).html() == '+ 顯示')||($(this).html() == '- 隱藏')) {
				$(this).html('- 隱藏');
			} else {
				$(this).html('- contract');
			}
		}
		return $(this);
	};
	

})(jQuery)

/*--------------------------*/
/*-- FUNCTION JQUERY MAIN --*/
/*--------------------------*/

jQuery(function($) {

$(document).ready(function(){

	$('.notification').customFadeTo(1, 0.8);

	$('.menu a').tooltip({
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		opacity: 0.95, 
		fade: 250,
		extraClass:'tooltip-width tooltip-uppercase'	
	});
	
	$('#site-navigation a,#logo a').tooltip({
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		opacity: 0.95, 
		fade: 250,
		extraClass:'tooltip-uppercase'	
	});

	/*-- SITE NAVIGATION ANIMATION --*/
	var button_alpha = 0.5;
	$('#site-navigation ul li').each( function(){ 
		$(this).fadeTo('normal',button_alpha);									   
		$(this).hover(function(){		
			$(this).fadeTo('fast',1);
		},function(){
			$(this).fadeTo('fast',button_alpha);
		});
	});

	
	/*-- FEATURED NAVIGATION CONSTRUCT --*/
	var counter = 1;
	if($('#featured-pre-list li').length > 0) {
		
		$('#featured-navigation').prepend('<ul id="featured-nav-list">');
		$('#featured-pre-list li').each(function(){
			var id = $(this).attr('id');
			if( counter == 1)
				$('#featured-nav-list').append($('<li class="'+id+' selected">'+counter+'</li>'));
			else
				$('#featured-nav-list').append($('<li class="'+id+'">'+counter+'</li>'));
			counter++;
		});
	}
	
	var featured_button_alpha = 0.8;
	var featured_entry_prefix = 'featured-entry-';
	counter--;
	
	$('#featured-nav-list li').fadeTo('fast',featured_button_alpha );
	
	var current_featured = 0, old_featured = counter;
	
	/*-- FEATURED NAVIGATION ANIMATION --*/
	$('#featured-nav-list li').click( function() {
		var link = '#' + $(this).attr('class');
		$(this).addClass('selected');
		$(this).siblings().removeClass('selected');
		$(link).each(function() {
			if($(this).hasClass('hide')) {
				$(this).hide().removeClass('hide').customFadeIn(900);
				$(this).siblings().customFadeOut(900).addClass('hide').show();
			}
		});	
	});
	
	
	/*-- FEATURED CAPTION ANIMATION --*/
	var caption_visible = false;
	var show_caption = function() {
		if(!caption_visible) {
			caption_visible = true;
			$('.featured-caption').css('border-left','5px solid #FFFFFF');								
			$('.featured-caption').animate({borderLeftWidth:'5px'},10);
			$('.featured-caption').children().removeClass('hide').hide();
			$('.featured-caption').removeClass('hide').css({width:"0px"}).animate({width:"150px"}, 200);
			$('.featured-caption').children().customFadeIn(600);
		}
	}
	var hide_caption = function() {
		if(caption_visible) {
			$('.featured-caption').children().customFadeOut(200);
			$('.featured-caption').animate({width:"0px"}, 600);
			$('.featured-caption').children().addClass('hide').show();
			$('.featured-caption').animate({borderLeftWidth:'0px'},200);
			caption_visible = false;
		}
	}

	/*-- FEATURED SLIDE SHOW ANIMATION --*/
	var featured_timeout;
	var caption_show_timeout;
	var caption_hide_timeout;	

	$('.featured-caption').addClass('hide');
	$('.featured-image').hover(function(){
		// Clear all timers and slide show and show caption
		clearTimeout(featured_timeout);
		clearTimeout(caption_show_timeout);
		clearTimeout(caption_hide_timeout);
		setTimeout(show_caption, 0);
	},function(){
		// Hide caption and resume slide show
		setTimeout(hide_caption, 0);
		featured_timeout = setTimeout(rotate_featured, 3000);
	});

	// Rotate featured entries
	var rotate_featured = function() {
		current_featured = (old_featured + 1) % counter;
		$('#featured-nav-list li.'+featured_entry_prefix+current_featured).trigger('click');
		caption_show_timeout = setTimeout(show_caption,1000);
		caption_hide_timeout = setTimeout(hide_caption,10000);
		old_featured = current_featured;
		featured_timeout = setTimeout(rotate_featured, 11000);
	}
	
	// Initiate slide show
	caption_show_timeout = setTimeout(show_caption,1000);
	caption_hide_timeout = setTimeout(hide_caption,10000);
	featured_timeout = setTimeout(rotate_featured, 11000);


	/*-- FEATURED NAVIGATION ANIMATION --*/
	$('#featured-nav-list li').click( function() {
		var link = '#' + $(this).attr('class');
		$(this).addClass('selected');
		$(this).siblings().removeClass('selected');
		$(link).each(function() {
			if($(this).hasClass('hide')) {
				$(this).hide().removeClass('hide').customFadeIn(900);
				$(this).siblings().customFadeOut(900).addClass('hide').show();
			}
		});	
	});

	/*-- ENTRY META ANIMATION --*/
	$('.entry-meta').prepend($(this).children('div'));
	$('.entry-meta div.tags-meta,.entry-meta div.comments-meta').hide();
	$('.entry-meta img.tag-meta').toggle( function(){
		$(this).siblings('div.tags-meta').each( function(){
			$(this).fadeTo(0,0).slideDown('fast').fadeTo('slow', 0.9);
		});
	}, function(){
		$(this).siblings('div.tags-meta').fadeTo('slow',0).slideUp('fast');
	});
	$('.entry-meta img.comment-meta').toggle( function(){
		$(this).siblings('div.comments-meta').each( function(){
			$(this).fadeTo(0,0).slideDown('fast').fadeTo('slow', 0.9);
		});
	}, function(){
		$(this).siblings('div.comments-meta').fadeTo('slow',0).slideUp('fast');
	});
	
	
	if($('.page-messages').length > 0){
	
	}else{
		
		var collapsed_meta = true;
		var collapsed_comments = true;
		var collapsed_respond = true;
		
		if((location.href.indexOf('#comment') != -1)||(location.href.indexOf('?replytocom') != -1)) {
			collapsed_comments = false;
			$('#comments-body-ctrl').expandContract('contract') ;
		}else{
			$('.comment-body').fadeOut(0);	
			$('#comments-body').collapseFadeOut(0);	
			$('#comments-body-ctrl').expandContract('expand');
			$('.comment-title').animate({paddingLeft: "200px"}, 0);
			$('.comment-shade').animate({paddingLeft: "200px"}, 0);
		}
	
		if((location.href.indexOf('#respond') != -1)||(location.href.indexOf('?replytocom') != -1)) {	
			collapsed_respond = false;	
			$('#respond-body-ctrl').expandContract('contract');
		}else{
			$('#respond-body').collapseFadeOut(0);
			$('#respond-body-ctrl').expandContract('expand');
			$('.respond-title').animate({paddingLeft: "200px"}, 0);
			$('.respond-shade').animate({paddingLeft: "200px"}, 0);
		}
		
		$('#meta-body').collapseFadeOut(0);
		$('.meta-title').animate({paddingLeft: "200px"}, 0);
		$('.meta-shade').animate({paddingLeft: "200px"}, 0);
		
	}
		
	$('#meta .meta-title').click(function(){
		if(!collapsed_meta){
			$(this).animate({paddingLeft: "200px"}, 200);
			$('.meta-shade').animate({paddingLeft: "200px"}, 200);
			
			$('#meta-body').collapseFadeOut('slow');
			collapsed_meta = true;
			$('#meta-body-ctrl').expandContract('expand');
		}else{
			$('#meta-body').expandFadeIn('slow');
			collapsed_meta = false;
			$('#meta-body-ctrl').expandContract('contract');
			$(this).animate({paddingLeft: "0"}, 200);
			$('.meta-shade').animate({paddingLeft: "10px"}, 200);
		}
	});
	
	$('#comments .comment-title').click(function(){
		if(!collapsed_comments){
			$('.comment-title').animate({paddingLeft: "200px"}, 0);
			$('.comment-shade').animate({paddingLeft: "200px"}, 0);
			
			$('.comment-body').customFadeOut('slow');
			$('#comments-body').collapseFadeOut('slow');
			collapsed_comments = true;
			$('#comments-body-ctrl').expandContract('expand');
		}else{
			$('.comment-body').customFadeIn('slow');
			$('#comments-body').expandFadeIn('slow');
			collapsed_comments = false;
			$('#comments-body-ctrl').expandContract('contract');
			
			$('.comment-title').animate({paddingLeft: "0"}, 0);
			$('.comment-shade').animate({paddingLeft: "10px"}, 0);
		}
	});
	
	$('#respond .respond-title').click(function(){
		if(!collapsed_respond){
			$('.respond-title').animate({paddingLeft: "200px"}, 0);
			$('.respond-shade').animate({paddingLeft: "200px"}, 0);
			$('#respond-body').collapseFadeOut('slow');
			collapsed_respond = true;
			$('#respond-body-ctrl').expandContract('expand');
		}else{
			$('#respond-body').expandFadeIn('slow');
			collapsed_respond = false;
			$('#respond-body-ctrl').expandContract('contract');
			$('.respond-title').animate({paddingLeft: "0"}, 0);
			$('.respond-shade').animate({paddingLeft: "10px"}, 0);
		}
	});


	$('#text-349325301').hover(function(){
		$('#friend_connect_alert').expandFadeIn('normal');	
	},function(){
		$('#friend_connect_alert').collapseFadeOut('fast');
	});
	
	$('#commentform').validate();


});

});