/**
 *  basics.js: Some JS Basics for the search box, external links, social media buttons and hover buttons in general!
 *
 *  By Designimate Studios
 *  http://www.designimatestudios.com/
 */

  //Search box
	var used = false;
	var search = document.getElementById('searchBox').getElementsByTagName('form')[0].query;
	
	search.onblur=function(){resSearch(this);};
	search.onfocus=function(){clrSearch(this);};
	search.form.onsubmit=function(){return used;}
	
	function clrSearch(el){
		if(!used){
			el.value="";
			used=true;
		}
	}
	function resSearch(el){
		if(el.value==""){
			el.value="Search Designimate";
			used=false;
		}
	}
	
	clrSearch(search);
	resSearch(search);
	
  //External links
	var anchors = document.anchors;  
	for (var i=0; i<anchors.length; i++) {  
		if (anchors[i].getAttribute("rel") == "ext") 
			anchors[i].target = "_blank";  
	}
	
  //Social media buttons
	var connectImgs = (gi=='index')? document.getElementById('IndexConnect').getElementsByTagName('img') : document.getElementById('connect').getElementsByTagName('img');
	var ini_srcs = new Array();
	var new_srcs = new Array();
	
	for(i=0;i<connectImgs.length;i++){ 
		//All this crap because of IE6'S PNGHack conflicts
		ini_srcs[i] = connectImgs[i].src;
		new_srcs[i]=ini_srcs[i].substring(0,ini_srcs[i].lastIndexOf("A"))+'B'+ini_srcs[i].substring(ini_srcs[i].lastIndexOf("."),ini_srcs[i].length);
		//Preload them
		img = new Image()
		img.src=new_srcs[i];
		connectImgs[i].id = i;
		//End of crap
		connectImgs[i].onmouseover=function(){this.src=new_srcs[this.id];};
		connectImgs[i].onmouseout=function(){this.src=ini_srcs[this.id];};
	}

  //Hover buttons in general
	function imgHoverOn(g){
			gg=g.src;
			tu=gg.lastIndexOf(".");
			tt=gg.lastIndexOf("_");
			g.src=gg.substring(0,tt)+'_B'+gg.substring(tu,gg.length);
	}

	function imgHoverOut(g){
			gg=g.src;
			tu=gg.lastIndexOf(".");
			tt=gg.lastIndexOf("_");
			g.src=gg.substring(0,tt)+'_A'+gg.substring(tu,gg.length);
	}

