$(document).ready(function(){

//toltips
	$('.tags a').each(function(){
      // Create image content using websnapr thumbnail service
      var content = '<img src="http://images.websnapr.com/?size=size&key=Fl78vRwnj5uu&url=url';
      content += $(this).attr('href');
      content += '" alt="Loading thumbnail..." height="152" width="202" />';
      
      // Setup the tooltip with the content
      $(this).qtip(
      {
         content: content,
         position: {
            corner: {
               tooltip: 'bottomMiddle',
               target: 'topMiddle'
            }
         },
         style: {
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: 'cream'
         }
      });
   });


//Validasi kontak pesan
	$("#form_contact").validate({
		rules: {
			nama: "required",
			email: {
				required: true,
				email: true
			},
			tujuan: "required",
			pesan: "required",
			judul: "required",
			code: {
				required: true,
				remote: "ajax_captcha.php"
			}
		},
		messages: {
			nama: "Mohon isi nama lengkap anda",
			email: "Masukkan alamat email valid anda",
			tujuan: "Silahkan pilih tujuan pesan anda",
			judul: "Mohon isi judul pesan anda",
			pesan: "Mohon isi pesan anda",
			code: "Jumlahkan angka yg ada dibawah"
		}
	});
	
//Validasi konfirmasi pembayaran
	$("#form_conform").validate({
		rules: {
			nama: "required",
			email: {
				required: true,
				email: true
			},
			no_invoice: {
				required:true,
				number:true
			},
			tgl_bayar: {
				required: true,
				dateISO:true
			},
			jml_bayar: "required",
			bank_tujuan: "required",
			bank_user: "required",
			nm_rek: "required",
			no_rek: "required",
			nm_domain: "required",
			pesan: "required",
			tipe_transaksi: "required",
			code: {
				required: true,
				remote: "ajax_captcha.php"
			}
		},
		messages: {
			nama: "Mohon isi nama lengkap anda",
			email: "Masukkan alamat email valid anda",
			no_invoice: "Masukkan no invoice anda",
			tgl_bayar: "Isi dengan format ( yyyy/mm/dd )",
			jml_bayar: "Jumlah transaksi anda",
			bank_tujuan: "Pilih bank tujuan anda",
			bank_user: "Pilih bank yang anda gunakan",
			nm_rek: "Masukkan nama rekening anda",
			no_rek: "Masukkan no rekening anda",
			nm_domain: "Masukkan nama domain anda",
			pesan: "Mohon isi pesan anda",
			tipe_transaksi: "Pilih transaksi anda",
			code: "Jumlahkan angka yg ada dibawah"
		}
	});
	
//treview
	$("#navigation").treeview({
	animated: "fast",
	persist: "location",
	collapsed: true,
	unique: true
	});

//colorbox
	$(".ex01").colorbox({width:"50%", inline:true, href:"#aff01"});
	$(".ex02").colorbox({width:"50%", inline:true, href:"#aff02"});
	$(".ex03").colorbox({width:"50%", inline:true, href:"#aff03"});
	$(".ex04").colorbox({width:"50%", inline:true, href:"#aff04"});
	$(".ex05").colorbox({width:"50%", inline:true, href:"#aff05"});
	
//select form
	$(".confirmation li").eq(0).addClass("active");
	$('.confirmation li').click(function(){
		$(this).toggleClass("active");
		$(this).siblings('.confirmation li').removeClass("active");
	}).mouseover(function() {
		$(this).css('backgroundColor','#999999');
	}).mouseout(function() {
		$(this).css('backgroundColor','');	
	});
	
//select on tab
	$('.data_input input, .data_input textarea, .data_input select').focus(function(){
		$('.confirmation li').removeClass("active");
		$(this).parent().parent().toggleClass("active");
	});


//newslite
	/*
	$(".newsticker-jcarousellite").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 1,
		auto:4000,
		speed:2000
	});
	*/
	
//slide circle	
	$(function() {
		$('#headline_promo, #headline_promo_right').cycle({ 
		fx:    'scrollLeft',
		pager: '#headline_page, #headline_page_right'
		});
	});

//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;								
	});
	
//accordion		
	$(".accordion h3").eq(0).addClass("active");
	$(".accordion .accor_content").eq(0).show();
	$(".accordion h3").click(function(){
		$(this).next(".accor_content").slideToggle("slow")
		.siblings(".accor_content:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
		
	$(".accordion02 h3").eq(0).addClass("active");
	$(".desc").eq(0).show();
	$(".accordion02 h3").click(function(){
		$(this).next(".desc").slideToggle("slow")
		.siblings(".desc:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

//slide
	$(".bt_testimonial").click(function(){
		$(".add_comment").slideToggle("fast");
	}).mouseover(function() {
		$(".bt_testimonial").css('cursor','pointer');
	});
	
	$(".syarat").click(function(){
		$(".content_box02").slideToggle("slow");
	}).mouseover(function() {
		$(".syarat").css('cursor','pointer');
	});
	
	
//innerfade
	$('#testimonial').innerfade({ 
		animationtype: 'fade', 
		speed: 800, 
		timeout: 5000, 
		type: 'random', 
		containerheight: '150px' 
	});
	
	$('.slide_product').innerfade({ 
		animationtype: 'fade', 
		speed: 800, 
		timeout: 3000, 
		type: 'sequence', 
		containerheight: '325px' 
	}); 
						   
//block promo
	$(".on_promo").click(function(){
		window.location=$(this).find("a").attr("href");return false;
	}).mouseover(function() {
		$(this).css('cursor','pointer');
	}).mouseout(function() {
		$(this).css('cursor','');	
	});

	$(".list_layanan").mouseover(function() {
		$(this).css('backgroundColor','#D7D7D7');
	}).mouseout(function() {
		$(this).css('backgroundColor','');	
	});

});	


$(document).ready(function(){
						   
	$('#inputField').bind("blur focus keydown keypress keyup", function(){recount();});
	$('input.submitButton').attr('disabled','disabled');
	
	$('#tweetForm').submit(function(e){
	
		tweet();
		e.preventDefault();
	
	});
	
});


function recount()
{
	var maxlen=270;
	var current = maxlen-$('#inputField').val().length;
	$('.counter').html(current);
	
		
	if(current<0 || current==maxlen)
	{
		$('.counter').css('color','#FF0000');
		$('input.submitButton').attr('disabled','disabled').addClass('inact');
	}
	else
		$('input.submitButton').removeAttr('disabled').removeClass('inact');

	
	if(current<10)
		$('.counter').css('color','#990000');
	
	else if(current<20)
		$('.counter').css('color','#666666');

	else
		$('.counter').css('color','#999999');
	
}