/*
  EffectsPack
  EffectsPack requires Prototype(http://prototype.conio.net/) and
  Effects v2 (http://mir.aculo.us)
  Feel free to use under any conditions
  
  These effects are targeted to specific cases and thus will not work 
  under every scenerio.
*/

 EffectPack = {}


/*---------------------------------+
 |  Nested Unordered List Effects  |
 +---------------------------------+
*/

EffectPack.BlindToggle = function(element) {
  element = element.parentNode.getElementsByTagName('ul')[0];
  if(element.style.display == 'none') 
    new Effect2.BlindDown(element);
  else
    new Effect2.BlindUp(element);
}


EffectPack.MagicToggle = function(element) {
  element = element.parentNode.getElementsByTagName('ul')[0];
  if(element.style.display == 'none') 
    new Effect.Appear(element);
  else
    new Effect.Fade(element);
}
  

/*---------------------------------+
 |        ActiveTab                |
 +---------------------------------+
*/

EffectPack.TabToggle = function(element) {

  //First We control the look and feel of the active tab
  var tabs = $('tabs').getElementsByTagName('span');
  for(j = 0; j < tabs.length; j++) {
    link = tabs[j].getElementsByTagName('a')[0];
    link.id = "";
    tabs[j].id = "";
  }
  element.id = "current"
  element.parentNode.id = "active"
  
  //Hide all content containers
  contents = document.getElementsByClassName('tabset_content');
  for(var i = 0; i < contents.length; i++) {
    contents[i].style.display = 'none';
  }

  //Extract content container id from href
  // 
  // 
  tabname = element.getAttribute('href').replace(/^.*\#/,'');
  ele = $(tabname);
  
  //Magic Happens
  new Effect.Appear(ele);

}

//crapshoot
 
function item_added() {
  var li = $('commentList').getElementsByTagName('LI');
  new Effect.Appear(li[li.length-1]);
  Element.hide('comment_loading');
  Element.show('commentform');
  $('commentform').elements[2].value = '';
  $('commentform').elements[2].focus();
  $('form-submit-button').disabled = false;
}
function item_loading() {
  $('form-submit-button').disabled = true;
  Element.show('comment_loading');
}

window.onload = function() {
  if( $('commentform').elements[1].value != '' ) {
    Element.show('guest_url');
  }
}

//onclick clear searchbox

	function ClearSearchBy()
		{
		if (document.getElementById('q').value == 'Enter your search here.')
			{
			document.getElementById('q').value = '';
			}
		}



// don't do anything if you hit enter at a search


function comment_sent() {
	new Effect.Appear('commentsent');
	document.getElementById('contact_from').value = '';
	document.getElementById('contact_email').value = '';
	document.getElementById('contact_message').value = '';
}

//Stylesheet switcher

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// cool column resizing!

function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	var currentStyle = getActiveStyleSheet();
	
	if ( currentStyle != "fixed" )
	{
	if ( theWidth < 900 )
	{
		document.getElementById("others").style.width = "100%";

		document.getElementById("projects").style.width = "100%";
	}
	else
	{
		document.getElementById("others").style.width = "50%";

		document.getElementById("projects").style.width = "50%";
	}
	
	return true;
}
}




function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}

	return 0;
}


function rules(img_name,img_src) {
        document[img_name].src=img_src;
        }

        function rulesoff(img_name,img_src) {
        document[img_name].src=img_src;
        }