try
  {
      var selectedtitle=getCookie("color")
      var colors = new Array();
      setColorList();
      //putGoogleSearchscript();

          if (document.getElementById && selectedtitle!=null) {
            //load user chosen style sheet if there is one stored
            setStylesheet(selectedtitle)
      }
    else
      {
	var randomnumber=Math.floor(Math.random()*colors.length)
	  //pickup a random color and set
	  setStylesheet(colors[randomnumber])
	  setCookie("color",colors[randomnumber],5)
	  }
	google.load("search", "1");
	google.load("friendconnect", "1");	
  }catch (e) {
  alert(e);
}
/************************** for Google AJAX Search ***********************/
function putGoogleSearchscript() {
  var key = 'ABQIAAAAnm6m31gbt_LgIZtU-_qGiBThBUt7fkqr1-1qEAzJee11QsvofRTy2nXkrvK9WXLednMeftNTYIYc9w';
  var scriptTag=document.createElement('script');
  scriptTag.type = 'text/javascript';
  scriptTag.src='http://www.google.com/uds/api?file=uds.js&v=0.1&key=' + key ;
  var myElement = document.getElementsByTagName("head")[0];
  //alert(myElement);
/* this statement causes IE crash */
  myElement.appendChild(scriptTag);
}

function onLoadGSearch() {
  //alert("onload called");

  //try {      
	var options = {
		adsOptions: {
			client: 'pub-0224090403306930',
			adsafe: 'high', // safe ads
			language: 'en'
		}
	};
    var searchControl = new google.search.SearchControl();
    var drawOptions = new google.search.DrawOptions();

      var webSearch = new google.search.WebSearch(options);
      webSearch.setUserDefinedLabel("My Web");
      webSearch.setUserDefinedClassSuffix("webSearch");
      webSearch.setSiteRestriction("jigarshah.net");
      searchControl.addSearcher(webSearch);  
 
      var siteSearch = new google.search.WebSearch(options);
      siteSearch.setUserDefinedLabel("My Blog");
      siteSearch.setUserDefinedClassSuffix("siteSearch");
      siteSearch.setSiteRestriction("jigarashah.blogspot.com");
      searchControl.addSearcher(siteSearch);
	  
    drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_LINEAR);
    // Tell the searcher to draw itself and tell it where to attach
    searchControl.draw(document.getElementById("searchControl"), drawOptions);
    // Execute an inital search
    searchControl.execute("");
	/*}catch (e) {
	  $('<p>Cannot Initialise GoogleSearch</p>');
	  throw e;
	  }*/
}

function getCookie(Name) { 
  var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
  if (document.cookie.match(re)) //if cookie found
    return document.cookie.match(re)[0].split("=")[1] //return its value
      return null
      }

function setCookie(name, value, days) {
  var expireDate = new Date()
    //set "expstring" to either future or past date, to set or delete cookie, respectively
    var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
    document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function deleteCookie(name){
  setCookie(name, "moot")
    }

function setStylesheet(title) {
  var i, cacheobj
    for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
      if(cacheobj.getAttribute("rel").indexOf("style") != -1 && cacheobj.getAttribute("title")) {
	cacheobj.disabled = true
	  if(cacheobj.getAttribute("title") == title)
	    cacheobj.disabled = false //enable chosen style sheet
	      }
    }
}

function chooseStyle(styletitle, days) {
  if (document.getElementById) {
    setStylesheet(styletitle)
      setCookie("color", styletitle, days)
      }
}

function highlightlink(selectedlink){
  var menulinks=document.getElementById("colormenu").getElementsByTagName("a")
    //alert("no of elements : " + menulinks.length)

    for (var i=0; i<menulinks.length; i++)
      menulinks[i].className="" //deselect all links
		
	selectedlink.className="current" //select clicked link
	}
/************************* for navigation menu ************************************/
function menuHTML (menuHTML) {
  this.menuHTML = menuHTML;
}
function menuIndex (menuIndex) {
  this.menuIndex = menuIndex;
}

function setColorList() {
  var i, cacheobj;
  for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
    if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { 
      colors.push(cacheobj.getAttribute("title")) //store reference to alt stylesheets inside array	
	}
  }
  //alert(colors.toString());
}

function displayNavigationMenu(page) {

  var element = document.getElementById('navigation'); 
  if(element != null) {
    element.innerHTML = drawNavigationMenu(page);
  }
}

function drawNavigationMenu(currentPage) {
  //var menuHTML = '<p style="margin-left: 7px; width: 143px;">' ;
  var navMenuHTML = new menuHTML('<p style="margin-left: 7px; width: 143px;">');

  //0-root 3-parent 1-child; keep child only under a parent 
  var pages = new Array("0#Home:index.html;home.png", 
			"0#Blog:blog.html;blog.png", 
			"0#Lifestream:lifestream.html;lifestream.png", 						
			"0#Resume:resume.html;resume.png", 
			"0#Publications:publications.html;papers.png",
                        //"3#My Projects:myprojects.html;projects.png",
                        //"1#Data Acquisition System:myprojects2.html;das.png",
                        //"1#SecUp:myprojects3.html;project.png",
                        //"1#My Projects3:myprojects4.html;project.png",
			"0#Photos:photos.html;photos.png",
 			"0#Videos:videos.html;videos.png",
            		//"1#Mahabaleshwar:photos_mahabaleshwar.html;film.png",
			//"1#Lonavla:photos_lonavla.html;film.png",
			//"1#Matrix:photos_matrix.html;film.png",
			//"1#Nvsoft Diwali:photos_nvsoft_diwali.html;film.png",
			//"1#Muskan:photos_muskan.html;film.png",
			"0#Coolquotes:coolquotes.html;quotes.png", 
			"0#Slambook:slambook.html;slambook.png", 
			"0#Downloads:downloads.html;download.png", 
			"0#Links:links.html;links.png", 
			"0#Contact:contactme.html;contact.png");
                        //"0#Feeds:feeds.html;feed.png");
  

  for(var i=0; i<pages.length; i++) {
    var navLevel = parseInt(pages[i].substr(0,pages[i].indexOf("#")));
    var displayName = pages[i].substring(pages[i].indexOf("#") + 1,pages[i].indexOf(":"));
    var pageName = pages[i].substring(pages[i].indexOf(":") + 1, pages[i].indexOf(";"));
      var imageName = pages[i].substr(pages[i].indexOf(";") + 1);

    //alert(" navLevel " + navLevel + " displayName " + displayName + " pageName " + pageName + "imageName " + imageName);

    if(navLevel == 0) {
      if(currentPage == pageName) {
		navMenuHTML.menuHTML  = navMenuHTML.menuHTML+ getNavigationMenuLink(pageName ,displayName ,imageName, 'nav active')
	  }
      else {	
		navMenuHTML.menuHTML = navMenuHTML.menuHTML + getNavigationMenuLink(pageName, displayName, imageName, 'nav')
	  }
    } else if (navLevel == 3) { // If it encounters currentPage as Parent Page Link
      if(currentPage == pageName) {
		navMenuHTML.menuHTML = navMenuHTML.menuHTML + getNavigationMenuLink(pageName ,displayName , imageName, 'nav active')
	  i = displayParentChild(i,pages,navMenuHTML,currentPage);
      } else {
		navMenuHTML.menuHTML = navMenuHTML.menuHTML + getNavigationMenuLink(pageName ,displayName ,imageName ,'nav')
	  }
    } else if (navLevel == 1) { 
      // If it encounters currentPage as Child Page Link ; It goes back till it finds parent and Iterates parent till child
      //alert ('if == 1 CURRENT PAGE ' + currentPage  + ' pageName ' + pageName)
      if(currentPage == pageName) {
	//alert ('if == 1' + 'curr==page')
	while (i >= 0) { 
	  i--;
	  navLevel = parseInt(pages[i].substr(0,pages[i].indexOf("#")));
	  //alert ('going back ' + i + ' navLevel ' + navLevel )
	  if(navLevel == 3)
	    {
	      i = displayParentChild(i,pages,navMenuHTML,currentPage);
	      break;						
	    }
	}
      }
    }
  }
  navMenuHTML.menuHTML = navMenuHTML.menuHTML + '</p>';
  //alert(navMenuHTML.menuHTML);
  return navMenuHTML.menuHTML;	
}

function displayParentChild(index,pages,navMenuHTML,currentPage) {
    var navLevel = parseInt(pages[index].substr(0,pages[index].indexOf("#")));
    var displayName = pages[index].substring(pages[index].indexOf("#") + 1,pages[index].indexOf(":"));
    var pageName = pages[index].substring(pages[index].indexOf(":") + 1, pages[index].indexOf(";"));
	var imageName = pages[index].substr(pages[index].indexOf(";") + 1);
	//	alert("navLevel " + navLevel + " displayName " + displayName + " pageName " + pageName + " imageName " + imageName 
	//	  + " currentPage " + currentPage);
	//	navMenuHTML.menuHTML = navMenuHTML.menuHTML + getNavigationMenuLink(pageName ,displayName ,'nav active')
  while (true) { //Display all the child under this Parent
    index++;
	//alert("index " + index);
    navLevel = parseInt(pages[index].substr(0,pages[index].indexOf("#")));
    if (navLevel != 1) { //Break if no Child
      index--;//To revert if non child element found
      break;
    }
    displayName = pages[index].substring(pages[index].indexOf("#") + 1,pages[index].indexOf(":"));
    pageName = pages[index].substring(pages[index].indexOf(":") + 1, pages[index].indexOf(";"));
	imageName = pages[index].substr(pages[index].indexOf(";") + 1);
    if(currentPage == pageName) {
      navMenuHTML.menuHTML 
		= navMenuHTML.menuHTML + getNavigationMenuLink(pageName ,displayName ,imageName ,'nav sub active')
	}
    else {	
      navMenuHTML.menuHTML = navMenuHTML.menuHTML + getNavigationMenuLink(pageName, displayName, imageName,'nav sub')
	}
  }

  return index;
}
function getNavigationMenuLink(pageName,displayName, imageName, classType) {
  var navigationLink = '<a class="'+ classType + '" href="' + pageName + '">' + '<img alt="" src="images/' + imageName	
	+ '" />' + displayName + '</a><span class="hide"> | </span>' + '\n';
  //alert(navigationLink);
  return navigationLink;
}
/************************* end of navigation menu ************************************/

/************************* for Stylesheet Selection Menu **************************/
function displayColorSelectMenu() {
  var selectedColor = getCookie("color")
    if (selectedColor==null){
      alert('no cookies')//display default
    }
    else //set selected
      {
	var element = document.getElementById('colormenu'); 
	if(element != null) {
	  element.innerHTML = drawColorSelectMenu(selectedColor);
	}
      }
}
function drawColorSelectMenu(selectedColor) {

  //var colors = new Array("blue", "green", "orange", "purple", "red", "black");
  var menuHTML = '<ul><li><h3>Change Colour &raquo;</h3></li>' ;
  for(var i=0; i<colors.length; i++) {
	  if(selectedColor == colors[i]) {
		  menuHTML = menuHTML + getColorMenuLink(colors[i],'current');
	  }
	  else {	
		  menuHTML = menuHTML + getColorMenuLink(colors[i],'');
	  }
  }
  menuHTML = menuHTML + '</ul>';
  return menuHTML;	
}

function getColorMenuLink(color,classType) {
	var colorLink = '<li><a href="#" type="image" id="' + color 
		+ '" class="' + classType 
		+ '" onClick="chooseStyle(this.id, 60); highlightlink(this)"><img src="images/colors_' 
		+ color + '.jpg" alt="' + color + '" /></a></li>' + '\n';
	return colorLink;
}
/************************* End of Stylesheet Selection Menu **************************/

/** Code taken from Sample at Code.Google.com **/
/**
 * Lists blog entries from the specified JSON feed
 * by creating a new 'ul' element in the DOM.  Each
 * bullet is the title of one blog entry, and contains
 * a hyperlink to that entry's URL.
 */
var recent = {
	no_of_entries: 5,
	Feed: "photos",
	Type: "comments",
	DivID: "recent_comments",
	listEntries: function(json) {
		var ul = document.createElement('ul');
		//alert(json.feed.entry.length);
		if(json.feed.entry.length < this.no_of_entries){
			this.no_of_entries = json.feed.entry.length;
		}
		
		for (var i = 0; i < this.no_of_entries; i++) {
			var entry = json.feed.entry[i];
			var alturl;
			//alert(entry.link.length);
			for (var k = 0; k < entry.link.length; k++) {
				if (entry.link[k].rel == 'alternate') {
					alturl = entry.link[k].href;
					break;
				}
			}
			
			var li = document.createElement('li');
			var a = document.createElement('a');
			a.href = alturl;
			var auth = entry.title.$t;
			if(Feed == 'photo' && Type == 'comments') {         
				auth = auth + " - " + entry.content.$t;
			}
			if(Feed == 'blog' && Type == 'comments') {         
				auth = auth + " - " + entry.content.$t;
			}

			var txt = document.createTextNode(auth);
			a.appendChild(txt);
			li.appendChild(a);
			ul.appendChild(li);
		}
		document.getElementById(DivID).appendChild(ul);
		
	},
  
  search: function (username, feed ,type, no_of_entries, divid) {
		try {
			//alert('search['+type+']feedtype['+feedtype+']');
			this.no_of_entries = no_of_entries;
			this.removeOldQueryResults(divid)
			Feed = feed;
			Type = type;   
			DivID = divid;
			var script = document.createElement('script');
			if(Feed == "photo") {
				if(Type == 'comments') {
					script.setAttribute('src', 'http://picasaweb.google.com/data/feed/api/user/' 
										+ username +'?kind=' + "comment" 
										+ '&alt=json-in-script&callback=recent.listEntries');
				}
			} else if(Feed == "blog") {
				if(Type == 'comments') {
					script.setAttribute('src', 'http://' + username + '/feeds/' + 'comments' 
										+ '/default?alt=json-in-script&callback=recent.listEntries');
				} else if(Type == 'entries') {
					script.setAttribute('src', 'http://' + username + '/feeds/' + 'posts' 
										+ '/default?alt=json-in-script&callback=recent.listEntries');
				}
			} else if(Feed == "video") {
				
			}
			script.setAttribute('type', 'text/javascript');
			document.documentElement.firstChild.appendChild(script);
		}catch(e){
			alert(e);
		}
	},
  
	/**
	 * Removes results from the previous search, including
	 * the bullet list of blog entries and the script object
	 * used to obtain the feed.
	 */
	removeOldQueryResults:function (divid) {
		// Remove the script element used to perform the query.
		var script_nodes = document.getElementsByTagName('script');
		for (var i = 0; i < script_nodes.length; i++) {
			var cur_node = script_nodes[i];
			
			if (cur_node.src && cur_node.src.indexOf('json') != -1) {
				//alert('remove');
				cur_node.parentNode.removeChild(cur_node);
			}
		}
		
		// Remove the bullet list of blog entries.
		
		var div = document.getElementById(divid);
		
		if (div.firstChild) {
			div.removeChild(div.firstChild);
		}
	}
};

function checkIE() {
	var cookie = getCookie("iecheck"); 
	//var cookie = null;
	
  if (navigator.userAgent.indexOf("Firefox") != -1) {

  }
  if (navigator.userAgent.indexOf("MSIE") != -1) {
    
    if (cookie == null) {
      content = '<a class="overlay_close" href="javascript:setCookie(\'iecheck\', \'ie\', 15);hideOverlay(\'iewarning\');">close[x]</a><p>Still using non-standard, slow Browser ? Upgrade to Firefox. Better, Faster, Open <br /><a href="http://www.spreadfirefox.com/?q=affiliates&id=188350&t=213"><img style="padding:5px;" src="images/110x32_get.gif" /></a></p>';
      showOverlay('iewarning',content);
    }
  }
}
function hideOverlay(id){
	var overlay = document.getElementById(id);
	overlay.style.display = 'none';
	overlay.innerHTML = "";
    
}
function showOverlay(id,content){

    var objBody = document.getElementsByTagName("body").item(0);
	if(objBody){
		var iewarning = document.createElement('div');
		iewarning.setAttribute('id', id);
		iewarning.innerHTML = content;
		objBody.insertBefore(iewarning, objBody.firstChild);
	}else{
		alert('no body element. please add');
	}
}
//To print values on the page
function $(a) {
    document.write(a);
}

function showfbar(divid) {
var skin = {};
skin['BORDER_COLOR'] = '#cccccc';
skin['ENDCAP_BG_COLOR'] = '#cccccc';
skin['ENDCAP_TEXT_COLOR'] = '#333333';
skin['ENDCAP_LINK_COLOR'] = '#0000cc';
skin['ALTERNATE_BG_COLOR'] = '#ffffff';
skin['CONTENT_BG_COLOR'] = '#ffffff';
skin['CONTENT_LINK_COLOR'] = '#0000cc';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#333333';
skin['POSITION'] = 'bottom';
skin['DEFAULT_COMMENT_TEXT'] = '- add your comment here -';
skin['HEADER_TEXT'] = 'Comments';
google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
google.friendconnect.container.renderSocialBar(
 { id: divid,
   site: '08794474466032456174',
   'view-params':{"scope":"SITE","allowAnonymousPost":"true","features":"video,comment","showWall":"true"}
 },
  skin);
}

function showFriendWG(divid) {
var skin = {};
skin['HEIGHT'] = '300';
skin['BORDER_COLOR'] = '#cccccc';
skin['ENDCAP_BG_COLOR'] = '#cccccc';
skin['ENDCAP_TEXT_COLOR'] = '#333333';
skin['ENDCAP_LINK_COLOR'] = '#0000cc';
skin['ALTERNATE_BG_COLOR'] = '#ffffff';
skin['CONTENT_BG_COLOR'] = '#ffffff';
skin['CONTENT_LINK_COLOR'] = '#0000cc';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#333333';
google.friendconnect.container.setParentUrl('/' );
google.friendconnect.container.renderMembersGadget(
 { id: divid,
   site: '08794474466032456174'},
  skin);
} 
function showCommentWG(divid) {
var skin = {};
skin['BORDER_COLOR'] = '#cccccc';
skin['ENDCAP_BG_COLOR'] = '#cccccc';
skin['ENDCAP_TEXT_COLOR'] = '#333333';
skin['ENDCAP_LINK_COLOR'] = '#0000cc';
skin['ALTERNATE_BG_COLOR'] = '#ffffff';
skin['CONTENT_BG_COLOR'] = '#ffffff';
skin['CONTENT_LINK_COLOR'] = '#0000cc';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#333333';
skin['DEFAULT_COMMENT_TEXT'] = '- add your comment here -';
skin['HEADER_TEXT'] = 'Comments';
skin['POSTS_PER_PAGE'] = '5';
google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
google.friendconnect.container.renderWallGadget(
 { id: divid,
   site: '08794474466032456174',
   'view-params':{"disableMinMax":"false","scope":"SITE","allowAnonymousPost":"true","features":"video,comment","startMaximized":"true"}
 },
  skin);
}
function twitterWidget() {
	new TWTR.Widget({
		  version: 2,
		  type: 'profile',
		  rpp: 5,
		  interval: 6000,
		  width: 'auto',
		  height: 300,
		  theme: {
		    shell: {
		      background: '#bdbdbd',
		      color: '#000000'
		    },
		    tweets: {
		      background: '#fafafa',
		      color: '#291529',
		      links: '#0049c7'
		    }
		  },
		  features: {
		    scrollbar: true,
		    loop: true,
		    live: false,
		    hashtags: true,
		    timestamp: true,
		    avatars: false,
		    behavior: 'default'
		  }
		}).render().setUser('jigarshah').start();
}

function showRecommendWG(divid) {
var skin = {};
skin['BORDER_COLOR'] = '#cccccc';
skin['ENDCAP_BG_COLOR'] = '#cccccc';
skin['ENDCAP_TEXT_COLOR'] = '#333333';
skin['ENDCAP_LINK_COLOR'] = '#0000cc';
skin['ALTERNATE_BG_COLOR'] = '#ffffff';
skin['CONTENT_BG_COLOR'] = '#ffffff';
skin['CONTENT_LINK_COLOR'] = '#0000cc';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#7777cc';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#333333';
skin['HEADER_TEXT'] = 'User Recommended';
skin['RECOMMENDATIONS_PER_PAGE'] = '5';
google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
google.friendconnect.container.renderOpenSocialGadget(
 { id: divid,
   url:'http://www.google.com/friendconnect/gadgets/recommended_pages.xml',
   site: '08794474466032456174',
   'view-params':{"docId":"recommendedPages"}
 },
  skin);

  }

