﻿// AllSite Variables //
var url = location.href;
var title = document.title;
var desc = "";

var enURL = encodeURIComponent(url);
var enTITLE = encodeURIComponent(title);
var enDESC = "";

// Dropdown Menu - Enhance CSS Layout
function dropdown(dropdownId, hoverClass, mouseOffDelay) {
	if(dropdown = document.getElementById(dropdownId)) {
		var listItems = dropdown.getElementsByTagName('li');
		var links = dropdown.getElementsByTagName('a');
		
		for(var i = 0; i < listItems.length; i++) {
			listItems[i].onmouseover = function() { this.className = addClass(this); }
			listItems[i].onmouseout = function() {
				var that = this;
				setTimeout(function() { that.className = removeClass(that); }, mouseOffDelay);
				this.className = that.className;
			}
			listItems[i].onclick = function() {	this.className = removeClass(this); }
			
			if (links[i] == url){
				listItems[i].className = 'thisPage';
				listItems[i].parentNode.parentNode.className = 'thisPage';
				listItems[i].parentNode.parentNode.parentNode.parentNode.className = 'thisPage';
			}
		}
	}
	
	function addClass(li) { return li.className + ' ' + hoverClass; }
	function removeClass(li) { return li.className.replace(hoverClass, ""); }
}
dropdown('nav', 'sfhover', 250);

function createBookmark() {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.external.addPanel("Test", url,"");
	} else if ( window.external ) { // IE Favorite
		window.external.AddFavorite ( url, title );
	} else {
		var ua=navigator.userAgent.toLowerCase();
    	var isKonq=(ua.indexOf('konqueror')!=-1);
		var isMac=(ua.indexOf('mac')!=-1);
    	var selButton=isMac?'?':'CTRL';
    	if (isKonq){ alert('Please Use '+selButton+'+B to Bookmark'); }
    	else { alert('Please Use '+selButton+'+D to Bookmark'); }
	}
}

function sharePage (position){
	if(position == 'open'){
		var aLi = '<li><a onclick="window.open(this.href,\'\',\'toolbar=no,width=750,height=550,resizable=yes,scrollbars=yes\'); return false" href="http://';
		var s = new Array();
		s[s.length] = '<table style="border: 1px solid #ccc;" cellpadding="3" cellspacing="0" onmouseover="clearTimeout(t)" onmouseout="sharePage(\'close\')"><tr><td colspan="2"><div class="left" style="padding: 4px"><strong>Share & Bookmark</strong><span style="position: absolute; top 0; right: 3px"><img src="http://www.carcovers.org/favicon.ico" width="16" height="16" style="vertical-align: bottom" /> T.J. Cars</span></div></td></tr>';
    	s[s.length] = '<tr><td><ul>';
    	s[s.length] = '<li><a target="_blank" href="" id="bullEM">Email Page</a></li>';
    	s[s.length] = aLi+'twitter.com/?status='+enURL+'" id="bullTW">Twitter</a></li>';
    	s[s.length] = aLi+'facebook.com/share.php?u='+enURL+'" id="bullFB">Facebook</a></li>';
    	s[s.length] = aLi+'myspace.com/Modules/PostTo/Pages/?u='+enURL+'&amp;t='+enTITLE+'&amp;c='+enDESC+'" id="bullMS">MySpace</a></li>';
    	s[s.length] = '</ul></td><td><ul>';
    	s[s.length] = '<li><a href="javascript:createBookmark()" id="bullBM">Bookmark</a></li>';
    	s[s.length] = aLi+'google.com/bookmarks/mark?op=add&bkmk='+enURL+'&amp;title='+enTITLE+'&amp;annotation=" id="bullGO">iGoogle</a></li>';
    	s[s.length] = aLi+'digg.com/submit?url='+enURL+'&amp;media=news&amp;topic=autos" id="bullDG">Digg</a></li>';
    	s[s.length] = aLi+'delicious.com/save?v=5&noui&jump=close&url='+enURL+'&title='+enTITLE+'" id="bullDE">Delicious</a></li>';
    	s[s.length] = '</ul></td></tr>';
    	s[s.length] = '<tr><td colspan="2" align="center"><div style="font-size: 11px; padding: 2px"><em class="green">Like what you see?&nbsp; Help us spread the word!</em></div></td></table>';
    	document.getElementById("sharing").innerHTML = s.join("");
    }
    if(position == 'close'){
    	t = setTimeout(function() { document.getElementById("sharing").innerHTML = ""; }, 500);
    }
}
