/* ----------------------------- BROWSER SNIFFING VARS ----------------------------- */

var agt      = navigator.userAgent.toLowerCase();
var appVer   = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var is_opera = (agt.indexOf("opera") != -1);
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_firefox = (agt.indexOf("firefox") != -1);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);
}
var is_ie   = (iePos!=-1);
var is_ie5   = (is_ie && is_major == 5);
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_ie5up = (is_ie && is_minor >= 5);


////Common Functions///////////////////////////////////////////////////////////////////

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); if(x){return x;}else{return false;};
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}

function MM_displayLayers() { //v3.0
	var i,p,v,obj,args=MM_displayLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
	obj.display=v; }
}


function swapimg(i){
	MM_swapImage('rally_redblack','','/html/images/product_rally_'+i+'_big.jpg',1)
}

////use this for the dynamic popup layer///
function popup_Show(i,x){
	//getTellaFriendPosition(i,x); //lets set the position of the element
	popup_Position(i,x);
	MM_displayLayers(i,'','show'); //turn it on...

}

function popup_Hide(i){
	MM_displayLayers(i,'','hide'); //turn it on...
}

function popup_Position(i,y){
	obj=MM_findObj(y);
	popupobj=MM_findObj(i);
	//popupfixedlayer=MM_findObj(linkobj);
	//get popup objects location
	//ypopup=findPosY(popupfixedlayer);

	if(document.all){
		c = 9;
	}else{
		c = 0;
	}

	x = findPosX(obj) + 30;
	y = findPosY(obj) - 55;

	popupobj.style.top = y+'px' ;
	popupobj.style.left = x+'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getPosition(i){
	obj=MM_findObj(i);
	popupobj=MM_findObj('popup');

	x = findPosX(obj);
	y = findPosY(obj) - 115;


	popupobj.style.top = y+'px';
	popupobj.style.left = x+'px';


	MM_showHideLayers('popup','','show');

}

/////////////////////////////////////////////////////////////////////


function popup(link) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 600)/2, yOffset = (yMax - 400)/2;

    windowHandle = window.open(link,'','top='+yOffset+',left='+xOffset+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');
}

function win_popup(link,width,height) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;

    windowHandle = window.open(link,'','top='+yOffset+',left='+xOffset+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height);
}


function getdivWidth(id) {

   var mydiv = document.getElementById(id);

   var curr_width = parseInt(mydiv.style.width); // removes the "px" at the end
   //mydiv.style.width = (curr_width + 10) +"px";

}

function getdivHeight(id) {

   var mydiv = document.getElementById(id);

   var curr_height = parseInt(mydiv.style.height); // removes the "px" at the end
   //mydiv.style.width = (curr_width + 10) +"px";

}

function detectscroll(id){
	if ((document.getElementById(id).scrollHeight > document.getElementById(id).clientHeight) && is_win){
		if(is_ie5up){
			width = getscrollbarwidth();
			newwidth = 735 - width;
			//document.getElementById('shadow').style.width = newwidth+'px';
		}else{
			//document.getElementById('shadow').style.width = 718+'px';
			
		}
	}
}

function getscrollbarwidth() {  //ie only
	var a;
	var t = document.forms.f.elements.t;
	//var t = getElementById('t');
	t.wrap = 'off';
	a = t.offsetHeight;
	t.wrap = 'soft';
	a -= t.offsetHeight;
	t.value = a;
	return a;
}

/////////////////////////////////////////////////////////////////////////////////////
