
//
// Common variables
//
var ua = navigator.userAgent.toLowerCase(),
	isStrict = document.compatMode == 'CSS1Compat',
	isOpera = ua.indexOf("opera") > -1,
	isFirefox = ua.indexOf("firefox") > -1,
	isIE = ua.indexOf('msie') > -1,
	isIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/,
	isIE7 = ua.indexOf('msie 7') > -1,
	isBorderBox = isIE && !isStrict,
	isSafari = (/webkit|khtml/).test(ua),
	isSafari3 = isSafari && !!(document.evaluate),
	isGecko = !isSafari && ua.indexOf('gecko') > -1,
	isWindows = (ua.indexOf('windows') != -1 || ua.indexOf('win32') != -1),
	isMac = (ua.indexOf('macintosh') != -1 || ua.indexOf('mac os x') != -1),
	isLinux = (ua.indexOf('linux') != -1);
	
	if (isOpera) {
		browser = "Opera";
	} else if (isIE6) {
		browser = "IE6";
	} else if (isIE7) {
		browser = "IE7";
	} else if (isIE) {
		browser = "IE";
	} else if (isSafari) {
		browser = "Safari";
	} else if (isFirefox) {
		browser = "Firefox";
	} else {
		browser = "none";
	}


//
// Common functions
//

// dummy function
function go () {
}
/*
function stopSelection() {
	element.onselectstart = function() { return(false); };
	element.setAttribute('unselectable', 'on', 0);
}
if (isIE) {
	addLoadEvent(stopSelection);
}
*/
function getVariable (var1, var2) {
	if (this[var1]) {
		if (!var2) {
			return this[var1];
		} else {
			// class variable
			if (this[var1][var2]) {
				return this[var1][var2];
			}
		}
	}
	
	return "none";
}
function changeVariable (v, set) {
	if (this[v] !== undefined) {
		this[v] = set;
	}
}
function setCookie (v, set, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = v + '=' + escape(set) + ((expiredays === null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(v)
{
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(v + "=");
		if (c_start != -1) {
			c_start = c_start + v.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function callFunction (func, p1, p2, p3) {
	if (this[func]) {
		this[func](p1, p2, p3);
	}
}

function displayJBox (swfName, jbSpecial) {
	
	jbox.special = jbSpecial ? jbSpecial : undefined;
	
	// get the width / height
	switch (swfName) {
		case "jbox_info":
			flSize = [550, 440];
		break;
		case "listing_contact":
			flSize = [500, 450];
		break;
		case "listing_flag":
			flSize = [505, 355];
		break;
		case "listing_save":
			flSize = [500, 455];
		break;
		case "listing_email":
			flSize = [510, 450];
		break;
		case "contact":
			flSize = [505, 450];
		break;
		case "forgot_password":
			flSize = [400, 300];
		break;
		case "logout":
			flSize = [400, 200];
		break;
		case "login":
			flSize = [550, 400];
		break;
		case "help":
			flSize = [750, 500];
		break;
		case "infocenter":
			flSize = [800, 500];
		break;
		case "sitemap":
			flSize = [750, 455];
		break;
		default:
			return;
	}
	
	if (jbox.Showing) {
		
		// ensure a nice transition
		
		jbox.Ready = false;
		jbox.initialize(jbox.flashWidth, jbox.flashHeight);
		element.fade('jbox', 100, 0, 500);
		
		setTimeout("jbox.Showing=false", 500);
		setTimeout("jbox.initialize(" + Number(flSize[0]) + "," + Number(flSize[1]) + ",'" + swfName + "')", 520);
		setTimeout("element.fade('jbox', 0, 100, 500)", 530);
		setTimeout("jbox.Showing=true", 530);
		setTimeout("jbox.start()", 540);
		
	} else {
		jbox.initialize(Number(flSize[0]), Number(flSize[1]), swfName);
		jbox.start();
	}
}

function endJBox () {
	jbox.end ();
}


/* ----- ELEMENT FUNCTIONS ----- */

function thisMovie(movieName) {
	if (isIE) {
		return window[movieName];
	} else{
		if (!document[movieName]) {
			return false;
		}
		if(document[movieName].length !== undefined){
			return document[movieName][1];
		}
		return document[movieName];
	}
}

var slideSizeCur = [];
function slideSize (fl, w, h, totW, totH, speed, dirw, dirh, arrId)
{
	var a, done = false, nw = 0, nh = 0;
	
	// NO SLIDE: IE6
	/*
	if (isIE6) {
		if (totW) {
			thisMovie(fl).width = Math.round(totW);
		}
		if (totH) {
			thisMovie(fl).height = Math.round(totH);
		}
		return;
	}
	*/
	
	//
	// first verify that no two same slideSizes are on same object!!!
	//
	
	if (arrId === undefined) {
		
		// erase old slideSize call
		for (a in slideSizeCur) {
			if (slideSizeCur[a] == fl) {
				slideSizeCur[a] = undefined;
			}
		}
		
		// add new one
		slideSizeCur.push(fl);
		arrId = slideSizeCur.length - 1;
		
	} else {
		
		// die - there is a new slideSize call
		if (!slideSizeCur[arrId]) {
			return;
		}
	}
	
	
	//
	// Calculate & verify direction/speed
	//
	
	// Make sure they are numbers
	h = Number(h);
	totH = Number(totH);
	w = Number(w);
	totW = Number(totW);
	
	// verify direction
	if (!dirh) {
		if (h < totH) {
			dirh = 1;
		} else {
			dirh = -1;
		}
		if (w < totW) {
			dirw = 1;
		} else {
			dirw = -1;
		}
	}
	
	// verify speed
	if (!speed) {
		speed = 1;
	}
	
	
	//
	// Check whether position was reached; Detirmine next position; Change size
	//
	
	// See if desired size was reached
	if (totH && dirh > 0 && thisMovie(fl).height >= totH) { done = true; }
	if (totH && dirh < 0 && thisMovie(fl).height <= totH) { done = true; }
	if (totW && dirw > 0 && thisMovie(fl).width >= totW) { done = true; }
	if (totW && dirw > 0 && thisMovie(fl).width <= totW) { done = true; }
	if (done) {
		if (totW) {
			thisMovie(fl).width = Math.round(totW);
		}
		if (totH) {
			thisMovie(fl).height = Math.round(totH);
		}
		
		slideSizeCur[arrId] = undefined;
		return;
	}
	
	// width
	if (totW) {
		nw = w + ((totW - w) + 5) / 10;
		if (nw < 1) { nw = 1; }
		
		thisMovie(fl).width = Math.round(nw);
	}
	
	// height
	if (totH) {
		nh = h + ((totH - h) + (dirh * 5)) / (10 / speed);
		if (nh < 1) { nh = 1; }
		
		thisMovie(fl).height = Math.round(nh);
	}
	
	// For next time
	setTimeout("slideSize('" + fl + "'," + w + "," + nh + "," + totW + "," + totH + "," + speed + "," + dirw + "," + dirh + "," + arrId + ")",30);
}



function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function ()
		{
			if (oldonload) {
				oldonload();
			}
		};
		func();
	}
}


function flVars ()
{
	var ret = '', i, b;
	
	for (i = 0; i <= arguments.length; i++) {
		if (i == arguments.length) {
			b = "getVariable|browser";
		} else {
			b = arguments[i];
		}
		ret += 'js_' + b.replace("|", "_") + '=' + escape(flashtalk.callJavascript(b, 'js')) + '&';
	}
	
	return ret;
}

function setMovieFocus (flashMovie)
{
	if (isFirefox || isIE) {
		setTimeout('thisMovie("' + flashMovie + '").focus()', 100);
	}
}


/* ----- TABS ----- */

var tabLinks = [];
var contentDivs = [];



function showTab()
{
	var url, selectedId, id;
	
	url = this.getAttribute('href');
	selectedId = url.substring( url.lastIndexOf ( '#' ) + 1 );
	
	// Highlight the selected tab, and dim all others.
	// Also show the selected content div, and hide all others.
	for ( id in contentDivs ) {
		if ( id == selectedId ) {
			tabLinks[id].className = 'selected';
			contentDivs[id].className = 'tabContent';
		} else {
			tabLinks[id].className = '';
			contentDivs[id].className = 'tabContent hide';
		}
	}
	
	// Stop the browser from following the link
	return false;
}

function tabBlur ()
{
	this.blur();
}

function getFirstChildWithTagName( element, tagName )
{
	for ( var i = 0; i < element.childNodes.length; i++ ) {
		if ( element.childNodes[i].nodeName == tagName ) {
			return element.childNodes[i];
		}
	}
}

function tabsInit()
{
	var tabListItems, tabLink, id, i;
	
	// Grab the tab links and content divs from the page
	tabListItems = document.getElementById('tabs').childNodes;
	for (i = 0; i < tabListItems.length; i++) {
		if (tabListItems[i].nodeName == "LI") {
			tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
			id = tabLink.getAttribute('href').substring( tabLink.getAttribute('href').lastIndexOf ( '#' ) + 1 );
			tabLinks[id] = tabLink;
			contentDivs[id] = document.getElementById( id );
		}
	}
	
	// Assign onclick events to the tab links, and
	// highlight the first tab
	i = 0;
	for (id in tabLinks) {
		tabLinks[id].onclick = showTab;
		tabLinks[id].onfocus = tabBlur;
		
		if (i === 0) {
			tabLinks[id].className = 'selected';
		}
		i++;
	}
	
	// Hide all content divs except the first
	i = 0;
	for (id in contentDivs) {
		if (i++ !== 0) {
			contentDivs[id].className = 'tabContent hide';
		}
		i++;
	}
}



/* ----- embed WIDGETS ----- */

function insertTwitter ()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" width="290" height="350" id="TwitterWidget">' +
		'<param name="allowScriptAccess" value="always" />' +
		'<param name="allowFullScreen" value="false" />' +
		'<param name="movie" value="http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf" />' +
		'<param name="quality" value="high" />' +
		'<param name="bgcolor" value="#000000" />' +
		'<param name="FlashVars" value="userID=80350429&amp;styleURL=http://static.twitter.com/flash/widgets/profile/velvetica.xml" />' +
		'<embed src="http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf" quality="high" bgcolor="#000000" width="290" height="350" name="TwitterWidget" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="userID=80350429&amp;styleURL=http://static.twitter.com/flash/widgets/profile/velvetica.xml"></embed>' +
		'</object>');
}
function insertFacebook ()
{
//	document.write('<a href="http://www.facebook.com/pages/Equisellercom/152627473527" title="Equiseller.com" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;">Equiseller.com</a><span style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; line-height: 16px; font-variant: normal; font-style: normal; font-weight: normal; color: #555555; text-decoration: none;">&nbsp;|&nbsp;</span><a href="http://www.facebook.com/business/dashboard/" title="Make your own badge!" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;">Promote Your Page Too</a><br/><a href="http://www.facebook.com/pages/Equisellercom/152627473527" title="Equiseller.com" target="_TOP"><img src="http://badge.facebook.com/badge/152627473527.2335.1785466292.png" width="360" height="163" style="border: 0px;" /></a>');
	document.write('<script type="text/javascript">FB.init("d83e225edf4355f2cbb8eff2b5dd8eba");</script><fb:fan profile_id="152627473527" stream="" connections="10" width="300"></fb:fan><div style="font-size:8px; padding-left:10px"><a href="http://www.facebook.com/pages/Equisellercom/152627473527">Equiseller.com on Facebook</a> </div>');
}


/* ----- embed flash objects ----- */


function EmbedFlash (flashWidth, flashHeight, flashMovie, flashVars, loadtext, loader)
{
	// loader?
	var lClip = flashMovie;
	if (flashVars) {
		if (loadtext) {
			flashVars = 'ltxt=1&' + flashVars;
		}
		if (loader) {
			lClip = loader + '_loader';
		} else if (loader !== false) {
			lClip = 'as2_loader';
		}
		flashVars = 'clip=' + flashMovie + '&' + flashVars;
	}
	
	if (!flashVars) {
		flashVars = '';
	}
	
	var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		' width=' + flashWidth + ' height=' + flashHeight + ' id=' + flashMovie +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">' +
		'<param id="objectid_' + flashMovie + '" name="movie" value="/flash/' + lClip + '.swf?' + flashVars + '" />' +
		'<param name="wmode" value="opaque" />' +
		'<param name="quality" value="high" />' +
		'<param name="bgcolor" value="#ffffff" />' +
		'<param name="allowScriptAccess" value="always" />' +
		
		'<embed src="/flash/' + lClip + '.swf?' + flashVars + '"' +
		' width="' + flashWidth + '" height="' + flashHeight + '" name="' + flashMovie + '" id="embedid_' + flashMovie + '"' +
		' align="left" wmode="opaque" loop="false" quality="high" bgcolor="#ffffff"' +
		' allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">' +
		'<\/embed>' +
		'<\/object>';
	
	document.write(oeTags);
}

var loaded_main_js = true;