jQuery(document).ready(function($) {
    //lavaFlow();
    tabberPost();
    tabberComment();
    switchLang();
    headShow();
    changeSearch();
    
    /* quote animation */
    var iNumb = 0;
    getQuote(false);
    setTimeout('quoteAnimation()',40000);
});

var quoteAnimation = function() {
  testQuoteAnimation();
  setTimeout('quoteAnimation()',40000);
}

var getQuote = function() {
  var quote = new Array(
    "Meaning and Purpose, the cure for desperate and hopeless",
    "Be good, be brave, be a winner - Freelynx",
    "Life is beautiful mind - Yudiacro",
    "The lamps are different but the Light is the same - Rumi",
    "Meaning and Purpose, the cure for desperate and hopeless",
    "Life is beautiful mind - Yudiacro",
    "Meaning and Purpose, the cure for desperate and hopeless",
    "Be good, be brave, be a winner - Freelynx",
    "Meaning and Purpose, the cure for desperate and hopeless",
    "The lamps are different but the Light is the same - Rumi"
  );
  var randNumb=Math.floor(Math.random()*11);
  randNumb = (randNumb == '10') ? (randNumb - 1) : randNumb
  if(arguments[0]) return quote[randNumb];
  else $('#quote-animation').text(quote[randNumb]);
}

var testQuoteAnimation = function() {
  var text = $('#quote-animation').text();
  var textNew = (!arguments[0]) ? getQuote(true) : arguments[0];
  var oldTextLength = text.length;
  var newTextLength = textNew.length;
  var theLength = (oldTextLength <= newTextLength) ? newTextLength : oldTextLength;
    
  if(!arguments[1]) {
    iNumb = 0;
  } else iNumb = arguments[1];
  
  chunkTextNew = textNew.substring(0,iNumb);
  chunkTextOld = text.substring(iNumb++);
  newText = chunkTextNew + chunkTextOld;
  $('#quote-animation').text(newText);
  if(iNumb <= theLength) setTimeout('testQuoteAnimation("'+textNew+'",'+iNumb+')',100);
}

lavaFlow = function() {
  jQuery("#lava").lavaLamp({
    fx: "backout", 
    speed: 800,
    click: function(event, menuItem) {
      return true;
    }
  });
}

switchLang = function(lang) {
  checkLang();
  jQuery(".en").hide();
  jQuery(".id").show();
  if (lang == "lang_en") {
    jQuery(".en").show();
    jQuery(".id").hide();
  }
  else if (lang == "lang_id") {
    jQuery(".en").hide();
    jQuery(".id").show();
  }
}

checkLang = function() {
  var lang_en = getElementsByClass("en");
  var lang_id = getElementsByClass("id");
  if (!lang_en && !lang_id) alert("Sorry, this articles doesn't serve bilingual.");
  else if (lang_en && !lang_id) alert("Sorry, this article only serves in English.");
  else if (!lang_en && lang_id) alert("Maaf, artikel ini hanya ada dalam Bahasa Indonesia.");
}

getElementsByClass = function(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

tabberPost = function(tab) {
  jQuery(".p1").show();
  jQuery(".p2").css({"display":"none"});
  jQuery(".p3").css({"display":"none"});
  jQuery(".p4").css({"display":"none"});
  if (tab == "p1") {
    jQuery(".p1").show();
    jQuery(".p2").hide();
    jQuery(".p3").hide();
    jQuery(".p4").hide();
  }
  else if (tab == "p2") {
    jQuery(".p1").hide();
    jQuery(".p2").show();
    jQuery(".p3").hide();
    jQuery(".p4").hide();
  }
  else if (tab == "p3") {
    jQuery(".p1").hide();
    jQuery(".p2").hide();
    jQuery(".p3").show();
    jQuery(".p4").hide();
  }
  else if (tab == "p4") {
    jQuery(".p1").hide();
    jQuery(".p2").hide();
    jQuery(".p3").hide();
    jQuery(".p4").show();
  }
}

tabberComment = function(tab) {
  jQuery(".c1").show();
  jQuery(".c2").css({"display":"none"});
  jQuery(".c3").css({"display":"none"});
  if (tab == "c1") {
    jQuery(".c1").show();
    jQuery(".c2").hide();
    jQuery(".c3").hide();
  }
  else if (tab == "c2") {
    jQuery(".c1").hide();
    jQuery(".c2").show();
    jQuery(".c3").hide();
  }
  else if (tab == "c3") {
    jQuery(".c1").hide();
    jQuery(".c2").hide();
    jQuery(".c3").show();
  }
}

changeSearch = function(engine) {
  jQuery("#searchform").show();
  jQuery("#cse-search-box").css({"display":"none"});
  jQuery("#feedburner-email").css({"display":"none"});
  if (engine == "google") {
    jQuery("#searchform").hide();
    jQuery("#cse-search-box").show();
    jQuery("#feedburner-email").hide();
  }
  else if (engine == "feedburner") {
    jQuery("#searchform").hide();
    jQuery("#cse-search-box").hide();
    jQuery("#feedburner-email").show();
  }
  else {
    jQuery("#searchform").show();
    jQuery("#cse-search-box").hide();
    jQuery("#cse-search-box").hide();
  }
}

headShow = function() {
  jQuery('#leftclick').click(function() { coolSlider(500); });
  jQuery('#rightclick').click(function() { coolSlider(-500); });
}

coolSlider = function() {
  var leftCss = jQuery('#frameslider').css('left');
  leftCss = parseFloat(leftCss.split('px')[0]) + arguments[0];
  if((leftCss <= 0) && (leftCss >= -1600)) {
    jQuery('#frameslider').animate({ left:leftCss+'px' },800);
  }
  else return false;
}

function Bookmark() {
	title = "Alsandros";
	url = "http://wpjunction.com/themes/alsandros/";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}
