$(function () {
	
	
	
	$('a.twet').click(function(){
		window.open(this.href);
		return false;
	});
	
	$('a.forum').click(function(){
		window.open(this.href);
		return false;
	});
	
	$('html, body').animate({scrollTop:0}, 1);
	
	var $flag = false;
	$('.login').click(function(){
		if($flag == false){
			$(this).addClass('hoverlogin');
			$('.hiddenlogin').show();
			$flag = true;
			return false;
		}
		else{
			$(this).removeClass('hoverlogin');
			$('.hiddenlogin').hide();
			$('.error').html('').hide();
			$flag = false;
			return false;
		}
	});
	
	$("#photo").jcarousel({
		visible:3		
	});
	
	
	
	
	var search_text = "cari di sini";
	$("#cse-search-box input:text").attr ("value", search_text);
	$("#cse-search-box input:text").click (function () {
		if ($(this).attr ("value") == search_text) {
			$(this).attr ("value", "");
		}
	});
	$("#cse-search-box input:text").blur (function () {
		if ($(this).attr ("value") == "") {
			$(this).attr ("value", search_text);
		}
	});
	
	var search_text = "CARI EDISI, CTH KEYWORD: 15/XXXIII/2009";
	$("#searchedition #searchedtioncode").attr ("value", search_text);
	$("#searchedition #searchedtioncode").click (function () {
		if ($(this).attr ("value") == search_text) {
			$(this).attr ("value", "");
		}
	});
	$("#searchedition input:text").blur (function () {
		if ($(this).attr ("value") == "") {
			$(this).attr ("value", search_text);
		}
	});
	
	var search_text3 = "CARI BAND KESUKAAN LO";
	$("#form_search input:text").attr ("value", search_text3);
	$("#form_search input:text").click (function () {
		if ($(this).attr ("value") == search_text3) {
			$(this).attr ("value", "");
		}
	});
	
	var search_text4 = "CARI Member";
	$("#form_search_member input:text").attr ("value", search_text4);
	$("#form_search_member input:text").click (function () {
		if ($(this).attr ("value") == search_text4) {
			$(this).attr ("value", "");
		}
	});
	
	$("*").hover(function () {
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	});
	$("#menu_main li").hover (function () {
		$(this).children("ul").slideDown (250);
	}, function () {
		$(this).children("ul").slideUp (250);
	});
	$("#menu_main li").click (function () {
		$(this).children("ul").slideToggle (250);
	});
	$("#menu_lo").hover (function () {
		$(this).children("ul").slideDown ("fast");
	}, function () {
		$(this).children("ul").slideUp ("fast");
	});
	
	 $("#gallery li a[rel=gallery]").fancybox({
	        'transitionIn'      : 'elastic',
	        'transitionOut'     : 'elastic',
	        'titlePosition'     : 'over',
	        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
	            return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
	        }
	    });
	    	
		
	
	 $("ul li:visible:odd, ol li:visible:odd, .list .comment:visible:odd").addClass("odd");
		$("ul li:visible:even, ol li:visible:even, .list .comment:visible:even").addClass("even");
		$("ul li:visible:first-child, ol li:visible:first-child, .list .comment:visible:first-child").addClass("first");
		$("ul li:visible:last-child, ol li:visible:last-child, .list .comment:visible:last-child").addClass("last");
		
		$(".blocks_two > div.block:first-child").addClass("first");
		$(".blocks_two > div.block:last-child").addClass("last");
		
		$(".tablelist tr:visible:first").addClass ("first");
		$(".tablelist tr:visible:odd").addClass ("even");
		$(".tablelist tr:visible:even").addClass ("odd");
		$(".tablelist2 tr:visible:first").addClass ("first");
		$(".tablelist2 tr:visible:odd").addClass ("even");
		$(".tablelist2 tr:visible:even").addClass ("odd");
		
		$(".tablelist tr:visible:first td:visible:first").addClass ("first");
		$(".tablelist tr:visible:first td:visible:odd").addClass ("even");
		$(".tablelist tr:visible:first td:visible:even").addClass ("odd");
		$(".tablelist2 tr:visible:first td:visible:first").addClass ("first");
		$(".tablelist2 tr:visible:first td:visible:odd").addClass ("even");
		$(".tablelist2 tr:visible:first td:visible:even").addClass ("odd");
		
		$("#playlist .item:visible:first").addClass("first");
		$("#playlist .item:visible:odd").addClass("odd");
		$("#playlist .item:visible:even").addClass("even");
		
		$('html, body').animate({scrollTop:0}, 1);
		$(".tabshead > li, #menu_main li li, #links li.now li, .tabshead2 > li").click (function () {
			var temp = $(this).children ("a").attr ("href");
			temp = '#' + temp.split('#')[1];
			
			window.location = $(this).children ("a").attr ("href");
			if (temp != "#undefined" && $(temp).length > 0) {
				$(".tabshead > li").removeClass ("active");
				$(".tabshead2 > li").removeClass ("active");
				$(".tabs > .tab").hide ();
				$(temp).fadeIn (250);
				$(".tabshead > li a[href=" + temp + "]").parent ().addClass ("active");
				$(".tabshead2 > li a[href=" + temp + "]").parent ().addClass ("active");
				// $('html, body').animate({scrollTop:$(temp).offset().top}, 1000);
				
				return false;
			} else {
				window.location = $(this).children ("a").attr ("href");
			}
		});
		
		$(".tabs > div.tab:first-child").addClass ("first_tab");
		
		var myFile = document.location.toString();
		$(".tabs > div.tab").hide ();
		if (myFile.match('#')) {
			var myAnchor = '#' + myFile.split('#')[1];
			$(myAnchor).show ();
			$(".tabshead > li").removeClass ("active");
			$(".tabshead > li a[href=" + myAnchor + "]").parent ().addClass ("active");
			// $('html, body').animate({scrollTop:$(myAnchor).offset().top}, 1000);
		} else {
			$(".tabs > div.tab:first-child").show ();
		}
		
		$("body").append("<div class=\"tooltips\"></div>");
		$("a[title]").tooltip({
			tip:'.tooltips',
			effect:'slide'
		});
	
	if ($('#showemo').length) {
		$("#showemo").click(function () {
			$(".emoticons").slideToggle("fast");
			return false
		});
	}
	
	if ($('.scroll_vertical').length) {
		// main horizontal scroll 
		$(".scroll_vertical").scrollable({ 
			// basic settings 
			vertical: true,
			size: 1,
			clickable: false,
			loop: true,
			// class settings
			items: '.pages',
			item: '.page'
		}).navigator(".navigation ul.list").autoscroll(5000);
	}
	
	$(".navigation ul li").each(function(i){
	    $(this).addClass("nav" + (i + 1));
	});
	
	if ($('.scroll_horizontal').length) {
		// main vertical scroll 
		$(".scroll_horizontal").scrollable({ 
			// basic settings 
			vertical: false,
			size: 1,
			clickable: false,
			loop: true,
			// class settings
			items: '.pages',
			item: '.page'
		}).navigator(".navigation ul.list").autoscroll(5000); 
	}
	
	if ($('#comments').length) {
		$("#comments .content:contains('(mario)')").each(function () { $(this).html($(this).html().replace(/\(mario\)/g, '<img alt="Mario" src="http://i28.tinypic.com/33eljwh.png" width="" height="16"/>')) }); $("#comments .content:contains('(luigi)')").each(function () { $(this).html($(this).html().replace(/\(luigi\)/g, '<img alt="Mario" src="http://i36.tinypic.com/2w4a712.jpg" width="" height="16"/>')) }); $("#comments .content:contains('(yoshi)')").each(function () { $(this).html($(this).html().replace(/\(yoshi\)/g, '<img alt="Mario" src="http://i34.tinypic.com/25sv7sj.jpg" width="" height="16"/>')) }); $("#comments .content:contains('(headspin)')").each(function () { $(this).html($(this).html().replace(/\(headspin\)/g, '<img alt="Head Spin" src="http://statics.plurk.com/b0b0596acce9ffc1f2a27548aa642eaf.gif" width="" height="16"/>')) }); $("#comments .content:contains('(rock)')").each(function () { $(this).html($(this).html().replace(/\(rock\)/g, '<img alt="Rock" src="http://statics.plurk.com/1c890273544559b17f090d09238fa763.gif" width="" height="16"/>')) });
	}
	
	if ($('.terekspose').length) {
		$(".terekspose").expose({ 
			color: '#fff', 
			opacity: 0.7, 
			closeOnClick: false,
			closeOnEsc: false,
			api: true
		}).load(); 
	}
	
	if ($('#gallery_popup').length) {
		$("#gallery_popup").before('<div class="overlay" id="gallery_popup_window"><a class="prev">sebelum</a><a class="next">sesudah</a><div class="info"></div><div class="progress"></div></div>');
		$("#gallery_popup a").overlay({ 
			target: '#gallery_popup_window', 
			expose: { 
				color: '#333', 
				loadSpeed: 500, 
				opacity: 0.9 
			}
		}).gallery({ 
			speed: 800 
		});
	}
	
	
});

//ajax loading tag
function ajax_loading(tag_id)
{
	$("#" + tag_id).ajaxSend(function(){
   		//$(".content").animate({opacity:0.65},1);
		$(this).show();
 	});
	
	$("#" + tag_id).ajaxStop(function(){
		//$(".content").animate({opacity:1.0},1);
		$(this).hide();
 	});
	
}

function emoticon(c) {
	var a = document.commentForm.comment_content;
	c = " " + c + " ";
	if (a.createTextRange && a.caretPos) {
		var b = a.caretPos;
		b.text = b.text.charAt(b.text.length - 1) == " " ? b.text + c + " " : b.text + c;
		a.focus();
		focusobject = a
	} else {
		a.value += c;
		a.focus();
		focusobject = a
	}
	return false
}

var konami = "38,38,40,40,37,39,37,39,66,65".split(',');
var keyIndex = 0;
$(document).keydown(function(ev) { (konami[keyIndex] == ev.keyCode) ? keyIndex++:keyIndex = 0;
	if (keyIndex == konami.length) {
		if ($("#konamicode").length == 0) {
			$("body").prepend ('<div id="konamicode"><iframe title="YouTube video player" class="youtube-player" type="text/html" width="853" height="510" src="http://www.youtube.com/embed/tgbNymZ7vqY?rel=0" frameborder="0"></iframe></div>');
		}
		$("#konamicode").fancybox({ 
			'width': 480, 
			'height': 385, 
			'overlayColor': '#000000', 
			'overlayOpacity': 0.75, 
			'onClosed': function () {
				$('#konamicode').remove (); 
			}
		});
		$("#konamicode").trigger('click');
		keyIndex = 0;
	}
});
