/*
PID: 0002
 * YPBB v1 - jQuery scripts 
 *
 * Copyright (c) 2009 Sanjaya Gida
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 */
//slideshow
$(document).ready(function() {
	$('.tabb').bind('click', function() {
	//$(".tabb").click(function(){
		//alert(this.id);				
		$("#dodol").removeClass("term-tab");
		$("#dodol").removeClass("contactus-tab");
		$("#dodol").addClass(this.id);
		return false;
		//$("#pane4").css("visibility", "visible;") 
	}),
   	jQuery('#mycarousel').jcarousel({
		visible: 1,
		auto: 15, //speed
		wrap: 'last',
		scroll: 1,
		animation: 800,
		itemFirstInCallback: {onBeforeAnimation: mycarousel_itemFirstInCallback},
		initCallback: function(jc, state) { //override to make the pause work
     if (state == 'init') {
              jc.startAutoOrig = jc.startAuto;
              jc.startAuto = function() {
                if (!jc.paused) {
                  jc.startAutoOrig();
                }
              }
              jc.pause = function() {
                jc.paused = true;
                jc.stopAuto();
              };
              jc.play = function() {
                jc.paused = false;
                jc.startAuto();
              };

/*				$('#play').toggle(function() {
				jc.pause();
				$("#play").html("<img src='../images/play.png' width='12' height='11' alt='' border='0'/> Replay Slideshow");
			},function() {
				jc.play();
				$("#play").html("<img src='../images/pause.png' width='12' height='11' alt='' border='0'/> Pause&nbsp; Slideshow");
		});
*/				
		$('.jcarousel-control a').bind('click', function() {
			//alert ((this.id).indexOf("slide"));
			if ((this.id).indexOf("slide")==0) { //only work for slide link (not the Pause/replay link)
		   	    jc.scroll(jQuery.jcarousel.intval($(this).text()));
				jc.pause();
				//alert ($('#play').text().indexOf("Pause")==1);
				if ($('#play').text().indexOf("Pause")==1) { //change the pause/replay if clicked
					$("#play").html("<img src='images/play.png' width='12' height='11' alt='' border='0'/> Replay Slideshow");
				}
			}
//					$('#play').click();
       		return false;
		});
		
	    $('#play').bind('click', function() {
//					alert (jQuery(this).text());
//					alert ($(this).text().indexOf("Pause"));
			if ($(this).text().indexOf("Stop")==1) { //toggle
				jc.pause();
				$("#play").html("<img src='images/play.png' width='12' height='11' alt='' border='0'/> Replay Slideshow");
			} else {
				jc.play();
				$("#play").html("<img src='images/stop.png' width='12' height='11' alt='' border='0'/> Stop Slideshow");
			}
	        return false;
	    });				
		//Not use:
              /* $('li.jcarousel-item').mouseover(function() {
                  jc.pause();
              });
              $('li.jcarousel-item').mouseout(function() {
                  jc.play();
              });
		*/
            }
            jc.play();
	 }
	})
});
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));		
        return false;
    });

    jQuery('.btn').bind('click', function() {
		var iLen = String(jQuery(this).attr("href")).length;
   	    var gID = String(jQuery(this).attr("href")).substring(1); //ambil ID saja dari string btnID		
        carousel.scroll(jQuery.jcarousel.intval(gID));		
        return false;
    });
};
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
//	change color of active button
	//alert($("#slide" + (idx - 1)).text());
	/*$('a[@id*="slide"]').each(function(index) {
		$("#slide" + index).removeClass("slideaktif");
	});	*/
	$("#slide0, #slide1, #slide2").removeClass("slideaktif");
    $("#slide" + (idx - 1)).addClass("slideaktif");
//		alert("dodol");
};	


//popup	menu2 (right)
$(document).ready(function() {
	//1. tombol close
	//2. kursor
	//3. mouse over link - rubah dekorasi font saja krn kalau bg harus putih
	//4. click over link - munculkan ketika di click saja
	$("#management-close").click(function() {$("#management-content").fadeOut("fast");}),
	$("#donor-close").click(function() {$("#donor-content").fadeOut("fast");}),
	$("#partnership-close").click(function() {$("#partnership-content").fadeOut("fast");}),
	$("#management, #donor, #partnership").css("cursor", "pointer");
    $("#management").hover(function() {
		//$("#management").css("background-color","#a6967d");
		$("#management").css("font-weight","bold");
		$("#management").css("text-decoration","underline");
		//$("#donor-content").fadeOut("fast");
		//$("#partnership-content").fadeOut("fast");
	},function() {
		//$("#management").css("background-color","#fff");
		$("#management").css("font-weight","normal");
		$("#management").css("text-decoration","none");
	}),
    $("#management").click(function() {
		$("#management-content").fadeIn("fast");
		$("#donor-content").fadeOut("fast");
		$("#partnership-content").fadeOut("fast");
	},function() {}),
//	$("#management-content").hover(function() {}, function() {
//		$("#management-content").fadeOut("fast");
//	}),

    $("#partnership").hover(function() {
		$("#partnership").css("font-weight","bold");
		$("#partnership").css("text-decoration","underline");
//		$("#partnership-content").fadeIn("fast");
//		$("#management-content").fadeOut("fast");
//		$("#donor-content").fadeOut("fast");
	},function() {
		$("#partnership").css("font-weight","normal");
		$("#partnership").css("text-decoration","none");
	}),
    $("#partnership").click(function() {
		$("#management-content").fadeOut("fast");
		$("#donor-content").fadeOut("fast");
		$("#partnership-content").fadeIn("fast");
	},function() {}),
//	$("#partnership-content").hover(function() {}, function() {
//		$("#partnership-content").fadeOut("fast");
//	}),
    $("#donor").hover(function() {
		$("#donor").css("font-weight","bold");
		$("#donor").css("text-decoration","underline");	
//		$("#donor-content").fadeIn("fast");
//		$("#management-content").fadeOut("fast");
//		$("#partnership-content").fadeOut("fast");
	},function() {
		$("#donor").css("font-weight","normal");
		$("#donor").css("text-decoration","none");		
	}),
    $("#donor").click(function() {
		$("#management-content").fadeOut("fast");
		$("#donor-content").fadeIn("fast");
		$("#partnership-content").fadeOut("fast");
	},function() {})
//	$("#donor-content").hover(function() {}, function() {
//		$("#donor-content").fadeOut("fast");			
//	})
});

// MAP info
$(document).ready(function() {
    /*$("#combomap").bind('click', function() {
        alert($("#combomap").val());
    }); */
	$(".moreinfo").each(function(){
		var t;
		var isanimated = false;
		var isvisible = false;
		var popup = $(".floatingpanel",this);
		$(this).mouseover(function(){
			if (t) clearTimeout(t);
			if (!isvisible && !isanimated){
				//alert($(this).css("left"));							
				isanimated = true;
				popup.css({opacity:0,display:"block",marginTop:15}).animate({marginTop:0,opacity:1},300, function(){isanimated=false;isvisible=true;});
			} else {
				return;
			}
		}).mouseout(function(){
			if (t) clearTimeout(t);
			if (!isanimated && isvisible){
				t = setTimeout(function(){isanimated=true;popup.animate({marginTop:-10,opacity:0},100, function(){popup.css({display:"none"});isvisible=false;isanimated=false;});}, 100);
			} else {
				return;
			}
		});
	});

	//$("#combomap").val(1); //define first selected map
	$("#combomap").change(function() { 
		$(".map").hide();
		switch($("#combomap").val()) {
		case "1":					
			$("#indonesia").show();
			$("#map-text").html("Indonesia");
			break;
		case "2":				  
			$("#adonaralembata").show();
			$("#map-text").html("Adonara &amp; Lembata");
			break;
		case "3":				  
			$("#balinusapenida").show();
			$("#map-text").html("Bali & Nusa Penida");
			break;
		case "4":				  
			$("#flores").show();
			$("#map-text").html("Flores");
			break;
		case "5":				  
			$("#javamap").show();
			$("#map-text").html("Java");
			break;
		case "6":				  
			$("#kalimantan").show();
			$("#map-text").html("Kalimantan");
			break;
		case "7":				  
			$("#lombok").show();
			$("#map-text").html("Lombok");
			break;
		case "8":				  
			$("#raijuasavu").show();
			$("#map-text").html("Rai Jua &amp; Savu");
			break;
		case "9":				  
			$("#sulawesi").show();
			$("#map-text").html("Sulawesi");
			break;
		case "10":				  
			$("#sumba").show();
			$("#map-text").html("Sumba");
			break;
		case "11":				  
			$("#timoreleste").show();
			$("#map-text").html("Timor-Leste");
			break;
		case "12":				  
			$("#westtimor").show();
			$("#map-text").html("West Timor");
			break;
		//default:				  
		  //code to be executed if n is different from case 1 and 2
		  //alert($("#combomap").val());
		}
	});	
	// $("#combomap").change(); // jalankan kalau ada set di awal
});
function jumpmap(kk) {
	$("#combomap").val(kk);
	$("#combomap").change();
}

//* INIT VALUE AWAL MAP */
	$(".map").hide();
	$(".moreinfo").hide();
	$("#indonesia").show();	

/* Preload
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
//	alert(arguments[i]);
  }
} */
//$.preloadImages("images/partnership2.png", "images/management.png","images/donor.png","images/floatingpanel.gif", "images/floatingpanel5.png", "images/play.png");
//$.preloadImages("../images/partnership2.png", "../images/management.png","../images/donor.png","../images/floatingpanel.gif", "../images/floatingpanel5.png", "../images/play.png");