var page;
var select_tgl;
var select_thn;
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var name_day = currentTime.getDay();
var weekday=new Array(7);
var pilih=0;
var positions=0;
var menu = new Array(0,1,2,3,4,11,12,13,14,22,23,60,100,126,139);
var menu_name = new Array('BERITA UTAMA','NASIONAL','EKONOMI &amp; BISNIS','NUSA','METRO','INTERNASIONAL','ILMU &amp; TEKNOLOGI','BUDAYA','OPINI','GAYA HIDUP','OLAH RAGA','TEKNOLOGI INFORMASI','EDITORIAL','TEMPO JATENG','TEMPO MAKASSAR');

weekday[0]="Minggu";
weekday[1]="Senin";
weekday[2]="Selasa";
weekday[3]="Rabu";
weekday[4]="Kamis";
weekday[5]="Jumat";
weekday[6]="Sabtu";
var monthday=new Array(11);
monthday[0]="Januari";
monthday[1]="Februari";
monthday[2]="Maret";
monthday[3]="April";
monthday[4]="Mei";
monthday[5]="Juni";
monthday[6]="Juli";
monthday[7]="Agustus";
monthday[8]="September";
monthday[9]="Oktober";
monthday[10]="Novermber";
monthday[11]="Desember";

function menu_position(numbers){
	positions=numbers;
}

function arsip(){
	jQuery("#tanggal-head").html(select_tgl+"&nbsp;"+select_thn+"&nbsp;<button onClick='cari();'>Cari</button>");
	page='';
	pilih=0;
	jQuery("#judul-head").html('Memuat...');
	jQuery("#konten_utama").load("/_arsip.php?thn="+year+"&bln="+month, function(){
		jQuery("#judul-head").html('ARSIP');
		if(!jQuery("#canadaprovinces").length){
			jQuery("#img_cover").removeClass('hilang');
		}else{
			jQuery("#img_cover").addClass('hilang');
			zooming();
		}
	});
}

function to_arsip(date){
	page='';
	pilih=0;
	var dates = date.split("/");
	jQuery("#judul-head").html('Memuat...');
	jQuery("#konten_utama").load("/_news_arsip.php?date="+date, function(){
		jQuery("#judul-head").html('ARSIP');
		if(!jQuery("#canadaprovinces").length){
			jQuery("#img_cover").removeClass('hilang');
		}else{
			jQuery("#img_cover").addClass('hilang');
			jQuery("#tanggal-head").html(dates[2] + " " + monthday[parseInt(dates[1])-1] + " " + dates[0]);
			zooming();
		}
	});
}

function cari(){
	page='';
	pilih=0;
	jQuery("#judul-head").html('Memuat...');
	jQuery("#konten_utama").load("/_arsip.php?thn="+jQuery("#thn").val()+"&bln="+jQuery("#tgl").val(), function(){
		jQuery("#judul-head").html('ARSIP');
		if(!jQuery("#canadaprovinces").length){
			jQuery("#img_cover").removeClass('hilang');
		}else{
			jQuery("#img_cover").addClass('hilang');
			zooming();
		}
	});
}

function memuat(param,judul){	
	if(page != "/_config.php"+param) {
		jQuery.fn.pageSlideClose();
		page = "/_config.php"+param;
		pilih=0;
		
		jQuery("#judul-head").html('Memuat...');
		jQuery("#tanggal-head").html(weekday[name_day] + ", " + day + " " + monthday[month-1] + " " + year);
		
		jQuery("#konten_utama").load("/_config.php"+param, function(){
			jQuery("#judul-head").html(judul);
			if(!jQuery("#canadaprovinces").length){
				jQuery("#img_cover").removeClass('hilang');
			}else{
				jQuery("#img_cover").addClass('hilang');
				zooming();
			}
		});
	}
}

function mencari(){	
	jQuery.fn.pageSlideClose();
	pilih=0;
	var text_search = jQuery("#search").val();
	jQuery("#search").attr("disabled","disabled");
	jQuery("#judul-head").html('Memuat...');
	jQuery("#tanggal-head").html(weekday[name_day] + ", " + day + " " + monthday[month-1] + " " + year);
	
	jQuery("#konten_utama").load("/_search.php?judul="+text_search.substr(0,30), function(){
		jQuery("#judul-head").html("Cari: "+text_search);
		if(!jQuery("#canadaprovinces").length){
			jQuery("#img_cover").removeClass('hilang');
		}else{
			jQuery("#img_cover").addClass('hilang');
			zooming();
			jQuery("#search").val('');
		}
		jQuery("#search").removeAttr("disabled");
	});
	return false;
}

function isTouchDevice() {
   var el = document.createElement('div');
   el.setAttribute('ongesturestart', 'return;');
   if(typeof el.ongesturestart == "function"){
      return true;
   }else {
      return false
   }
}

function zooming(){
	if(isTouchDevice()==false){
		jQuery(".zoom").mouseover(function (e) {
			if (e.shiftKey) {
				var position = jQuery(this).position();
				var width = jQuery(this).width()*2;
				jQuery("#zoom").show();
				jQuery("#zoom").html("<div href='"+jQuery(this).attr('href')+"' class='"+jQuery(this).find("a").attr("id")+"'>"+jQuery(this).html()+"</div>");
				jQuery("#zoom").attr("style","font-size:30px;top:"+(position.top+70)+"px;left:"+(position.left+30)+"px;width:"+width+"px;");
				jQuery("#zoom").find("div").attr("style","padding-top: 5px;font-size:18px;");
				jQuery("#zoom").find("a").attr("style","font-size:30px;");
				jQuery("body").attr("style","cursor:help");
				jQuery("."+jQuery(this).find("a").attr("id")).pageSlide({ width: "88%", direction: "left" });
			}else{
				jQuery("#zoom").hide();
				jQuery("body").attr("style","cursor:pointer");
			}
		}).mouseout(function (e) { jQuery("body").attr("style","cursor:default"); });
	}
}

function geser(ids, arah){
	var config = {gliderid: "canadaprovinces",contentclass: "glidecontent",togglerid: "p-select",remotecontent: "",selected: pilih,persiststate: false,speed: 1000,direction: arah,autorotate: false}

	config.$glider=jQuery("#"+config.gliderid)
	config.$togglerdiv=jQuery("#"+config.togglerid)
	config.$toc=config.$togglerdiv.find(".toc")
	config.$next=config.$togglerdiv.find(".next")
	config.$prev=config.$togglerdiv.find(".prev")
	config.$prev.attr("buttontype", "previous")
	var selected=(config.persiststate)? featuredcontentglider.getCookie(config.gliderid) : config.selected
	config.selected=(isNaN(parseInt(selected))) ? config.selected : selected
	config.leftortop=(/up/i.test(config.direction))? "top" : "left"
	config.heightorwidth=(/up/i.test(config.direction))? config.$glider.height() : config.$glider.width()
	if (typeof config.remotecontent!="undefined" && config.remotecontent.length>0)
		featuredcontentglider.getremotecontent($, config)
	else
		featuredcontentglider.setuptoggler($, config)
	if(ids==0){	
		featuredcontentglider.glide(config, config.nextslideindex, "next");
	}else{
		featuredcontentglider.glide(config, config.prevslideindex, "previous");
	}
}

jQuery(document).ready(function() {
	memuat('','BERITA UTAMA');	
	var i=0;
	select_tgl = "<select name='tgl' id='tgl'>";
	for(i=1;i<=12;i++) select_tgl += "<option value='"+i+"' "+(i==month ? 'selected="selected"':'')+">"+monthday[i-1]+"</option>";
	select_tgl += "</select>";
	
	select_thn = "<select name='thn' id='thn'>";
	for(i=year;i>=2004;i--) select_thn += "<option value='"+i+"'>"+i+"</option>";
	select_thn += "</select>";	
	
	jQuery("#fixed").touchwipe({
		 wipeLeft: function() {pilih++;if(pilih >= jQuery(".toc").length) pilih=0;geser(0,"rightleft");},
		 wipeRight: function() {pilih--;if(pilih < 0) pilih=jQuery(".toc").length-1;geser(1,"leftright");},
		 wipeDown: function() {positions++;if(pilih >= menu.length) positions=0;memuat((positions==0 ? "":"?idcategory="+menu[positions]),menu_name[positions]);},
		 wipeUp: function() {positions--;if(positions < 0) positions=(menu.length-1);memuat((positions==0 ? "":"?idcategory="+menu[positions]),menu_name[positions]);},
		 min_move_x: 20,
		 min_move_y: 20,
		 preventDefaultEvents: true
	});
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer") jQuery("#konten_utama").attr('style',"width:100%;height:80%;");
	
	//title input type
        jQuery('input[name=\"search\"]').each(function(){
          this.value = jQuery(this).attr('title');
          jQuery(this).addClass('text-label');
          jQuery(this).focus(function(){
            if(this.value == jQuery(this).attr('title')) {
              this.value = '';
              jQuery(this).removeClass('text-label');
            }
          });
          jQuery(this).blur(function(){
            if(this.value == '') {
              this.value = jQuery(this).attr('title');
              jQuery(this).addClass('text-label');
            }
          });
        });
        //end title input type
	
});
