
$(document).ready(function() {


/*---- untuk login dan pendaftaran ----*/
$('#loading').ajaxStart(function() {
	$(this).show();

	$('#infobar').slideDown("slow");
	$('#infobar').html('<img src="./img_web/load.gif" border="0" /> Tunggu sebentar...');
	//$('#hasil').hide();
}).ajaxStop(function() {
	$(this).hide();

	//$('#infobar').slideUp("fast");
	$('#infobar').fadeIn('slow');
	//$('#hasil').fadeIn('slow');
});

function tunggu(){
		$('#infobar').slideDown("fast");
		$('#infobar').text('Tunggu sebentar...');
}
 
$('#pendaftaran').submit(function() {
	$.ajax({
		type: 'POST',
		url: './aksi_pendaftaran.php',//$(this).attr('action'),
		data: $(this).serialize(),
		success: function(data) {
				//$('#hasil').html(data);
				$('#infobar').html(data);
				//$('#infobar').css({'background-color':'#8ff287'});
		}
	})
	return false;
});

$('#kirimkan').submit(function() {
	$.ajax({
		type: 'POST',
		url: $(this).attr('action'),
		data: $(this).serialize(),
		success: function(data) {
				//$('#hasil').html(data);
				$('#infobar').html(data);
		}
	})
	return false;
});

$("#infobar").click(function(e){
	$('#infobar').slideUp("fast");
});
/*-------------------------------------*/

/*------------ efek link --------------*/
$(".hubungkan").click(function(e){
		//e.preventDefault();
		tunggu();
});
/*-------------------------------------*/
/*------------- select area -----------*/
$('.pilihkata').selectedTextSharer({
        lists:"Wikipedia (en),http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s,favicon|Google Maps,http://maps.google.com/?q=%s,favicon",
		title: 'Cari kata ini ...',
		borderColor: '#009900',
		hoverColor: '#FFFFCC'
});
/*-------------------------------------*/

/*-------- status progressbar ---------*/
$("#total_kuota").progressBar({ barImage: './img_web/progress/progressbg_yellow.gif'} );
$("#sisa_kuota").progressBar({ barImage: './img_web/progress/progressbg_green.gif'} );

/*
/-----------------------\
|						|
| Facebook toolbar		|
|						|
\-----------------------/
*/
	//Adjust panel height
	$.fn.adjustPanel = function(){ 
		$(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset subpanel and ul height
		
		var windowHeight = $(window).height(); //Get the height of the browser viewport
		var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel	
		var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
		var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)
		
		if ( panelsub >= panelAdjust ) {	 //If subpanel is taller than max height...
			$(this).find(".subpanel").css({ 'height' : panelAdjust }); //Adjust subpanel to max height
			$(this).find("ul").css({ 'height' : ulAdjust}); //Adjust subpanel ul to new size
		}
		else if ( panelsub < panelAdjust ) { //If subpanel is smaller than max height...
			$(this).find("ul").css({ 'height' : 'auto'}); //Set subpanel ul to auto (default size)
		}
	};
	
	//Execute function on load
	$("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
	$("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel
	
	//Each time the viewport is adjusted/resized, execute the function
	$(window).resize(function () { 
		$("#chatpanel").adjustPanel();
		$("#alertpanel").adjustPanel();
	});
	
	//Click event on Chat Panel + Alert Panel	
	$("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
		if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
			$(this).next(".subpanel").hide(); //Hide active subpanel
			$("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
		}
		else { //if subpanel is not active...
			$(".subpanel").hide(); //Hide all subpanels
			$(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
			$("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
			$(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
		}
		return false; //Prevent browser jump to link anchor
	});
	
	//Click event outside of subpanel
	$(document).click(function() { //Click anywhere and...
		$(".subpanel").hide(); //hide subpanel
		$("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
	});
	$('.subpanel ul').click(function(e) { 
		e.stopPropagation(); //Prevents the subpanel ul from closing on click
	});
	
	//Delete icons on Alert Panel
	$("#alertpanel li").hover(function() {
		$(this).find("a.delete").css({'visibility': 'visible'}); //Show delete icon on hover
	},function() {
		$(this).find("a.delete").css({'visibility': 'hidden'}); //Hide delete icon on hover out
	});

/*--------------------- Modal Dialog ---------------------*/
	$('a.pesan1').click(function() {
		$.fn.jmodal({
			data: { innerText: $(this).text() },
			title: 'Upss',
			content: 'Fitur musik belum tersedia',
			buttonText: { ok: 'Oke', cancel: 'No' },//buttonText: { ok: 'Yes,It is.', cancel: 'No' },
			fixed: true,
			okEvent: function(obj, args) {
			alert(obj.innerText);
			args.complete();
			}
		});
	});

	$('a.pesan2').click(function() {
		$.fn.jmodal({
			data: { innerText: $(this).text() },
			title: 'Upss',
			content: 'Fitur Galeri gambar belum tersedia',
			buttonText: { ok: 'Oke', cancel: 'No' },//buttonText: { ok: 'Yes,It is.', cancel: 'No' },
			fixed: true,
			okEvent: function(obj, args) {
			args.complete();
			}
		});
	});
	
	$('a.pesan3').click(function() {
		$.fn.jmodal({
			data: { innerText: $(this).text() },
			title: 'Upss',
			content: function(e) {
                        e.html('<img src="./img_web/load.gif" border="0" /> Tunggu sebentar...');
                        e.load('pesan/pesan_fb.htm');
                    },//'Fitur Facebook belum tersedia',
			buttonText: { ok: 'Oke', cancel: 'No' },//buttonText: { ok: 'Yes,It is.', cancel: 'No' },
			fixed: true,
			okEvent: function(obj, args) {
			//location.href='./?p=daftar';
			args.complete();
			}
		});
	});

	$('a.unggahfile').click(function() {
		$.fn.jmodal({
			data: { innerText: $(this).text() },
			title: 'Upss',
			content: function(e) {
                        e.html('<img src="./img_web/load.gif" border="0" /> Tunggu sebentar...');
                        e.load('pesan/pesan1.htm');
                    },
			buttonText: { ok: 'Oke', cancel: 'No' },
			fixed: true,
			okEvent: function(obj, args) {
			location.href='./?p=daftar';
			args.complete();
			}
		});
	});
	
	
})



