//Everything
// Browser detection, MUST BE FIRST in this file as it is used in subsequent functions
//in this file

// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav 	   = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                 && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2    = (is_nav && (is_major == 2));
var is_nav3    = (is_nav && (is_major == 3));
var is_nav4    = (is_nav && (is_major == 4));
var is_nav4up  = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav6    = (is_nav && (is_major == 5));
var is_nav6up  = (is_nav && (is_major >= 5));
var is_gecko   = (agt.indexOf('gecko') != -1);
var is_safari   = (agt.indexOf('safari') != -1);

var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3     = (is_ie && (is_major < 4));
var is_ie4     = (is_ie &&  (agt.indexOf("msie 4")!=-1) );
var is_ie4up   = (is_ie && (is_major >= 4));
var is_ie5     = (is_ie &&  (agt.indexOf("msie 5")!=-1) );
var is_ie5_5   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up   = (is_ie && !is_ie3 && !is_ie4 );
var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6     = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up   = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

var is_iframe_compliant = (is_ie5up || is_nav6up);

var is_win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var is_mac = (agt.indexOf("mac")!=-1);





/*
* This include is used to provide any page with a layer class that can
* be used to "wrap" an absolutely positioned layer with a uniform set
* of properties and methods regardless of browser.
*
* Note: this include relies on the commonScript.js include for the various
* global properties associated with browser detection.
*/

// Constructor function
function DynLayer(id,nestlayer1,nestlayer2) {  //parameters passed are all strings of layer IDs
	if (is_nav) {
		if (is_nav4) {
			switch(arguments.length){ //depending on the number of parameters passed, form reference path to new DynLayer
				case 1:
					this.css = eval("document."+id)
					break;
				case 2:
					this.css = eval("document."+nestlayer1+".document."+id)
					break;
				case 3:
					this.css = eval("document."+nestlayer2+".document."+nestlayer1+".document."+id)
					break;
				default:
					alert("Creating a new DynLayer has failed");
					break;
			}
			this.elmt = this.event = this.css;  //elmt is the same as css for NS4 - it's the actual layer element
			this.doc = this.css.document;
			this.w = this.css.clip.width;
			this.h = this.css.clip.height;
		} else if (is_nav6up) {
			this.elmt = document.getElementById(id);
			this.css = this.elmt.style;
			this.doc = document;
			this.w = this.elmt.offsetWidth;
			this.h = this.elmt.offsetHeight;
		}
		this.x = this.css.left;
		this.y = this.css.top;
	} else if (is_ie4up) {
		this.elmt = this.event = document.all[id];
		this.css = this.elmt.style;
		this.doc = document;
		this.x = this.elmt.offsetLeft;
		this.y = this.elmt.offsetTop;
		this.w = (is_ie4)? this.css.pixelWidth : this.elmt.offsetWidth;
		this.h = (is_ie4)? this.css.pixelHeight : this.elmt.offsetHeight;
	}
	this.id = id;
	this.obj = id + "DynLayer";
	eval(this.obj + "=this");
	//alert("\nthis.id: " + this.id + "\nthis.x: " + this.x + "\nthis.y: " + this.y + "\nthis.w: " + this.w + "\nthis.h: " + this.h);
}


// Standard functions to move and change visibility
DynLayer.prototype.moveTo = function(x,y) {
	if (x!=null) {
		this.x = x;
		if (is_nav6up) this.css.left = this.x + "px";
		else this.css.pixelLeft = this.x;
	}
	if (y!=null) {
		this.y = y;
		if (is_nav6up) this.css.top = this.y + "px";
		else this.css.pixelTop = this.y;
	}
}
DynLayer.prototype.moveBy = function(x,y) {
	if (x!=null) {
		this.x += x;
		if (is_nav) this.css.left = this.x;
		else this.css.pixelLeft = this.x;
	}
	if (y!=null) {
		this.y += y;
		if (is_nav) this.css.top = this.y;
		else this.css.pixelTop = this.y;
	}
}
DynLayer.prototype.show = function() {
	this.css.visibility = (is_nav4)? "show" : "visible"
}
DynLayer.prototype.hide = function() {
	this.css.visibility = (is_nav4)? "hide" : "hidden"
}

function getElmtRef(strElmtId) {
	if (!document.getElementById) {
		return document.all[strElmtId];
	} else {
		return document.getElementById(strElmtId);
	}
}

function findGlobalPosX(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 findGlobalPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
		curtop += 1;
	} else if (obj.y) {
		curtop += obj.y;
	}	
	return curtop;
}

function getMainTopPosition(refElmt, lyrElmt) {
	var adjustTop = 0;
	if (is_ie5 && is_mac){		
		adjustTop = 8;	
	}else if (is_safari){
		adjustTop = 12;	
	}else{
		adjustTop = 2;	
	}

	var mainTopPosition = findGlobalPosY(refElmt) + adjustTop;	
	return mainTopPosition;
}

function getMainLeftPosition(posElmt) {
	var adjustLeft = 0;	
	if (is_ie5 || is_ie5_5){
		if(is_ie5_5){
			adjustLeft = 88;
		}else{
			if (is_mac){
				adjustLeft = 81;
			}else{
				adjustLeft = 79;
			}	
		}			
	}else{
		adjustLeft = 89;	
	}
	var mainLeftPosition = findGlobalPosX(posElmt) + adjustLeft;	
	return mainLeftPosition;
}

function makeArray(len) {
    for (var i = 0; i < len; i++) this[i] = null;
	this.length = len;
}
	
topNavParents = new makeArray(4);		
	
topNavParents[0] = 'topNav_aboutus';
topNavParents[1] = 'topNav_services';
topNavParents[2] = 'topNav_clients';
topNavParents[3] = 'topNav_contact';

topNavChildren = new makeArray(1);		
	
topNavChildren[0] = 'topNavChild_aboutus';




var arrAboutUs = [['Vision','http://www.v12groupinc.com/about_us/vision.asp'],['History','http://www.v12groupinc.com/about_us/history.asp'],['Above/Below the Line Marketing','http://www.v12groupinc.com/about_us/above_below_marketing.asp'],['Management','http://www.v12groupinc.com/about_us/management.asp'],['News and Events','http://www.v12groupinc.com/about_us/news_events.asp'],['Careers','http://www.v12groupinc.com/about_us/careers.asp']]; 
var arrServices = [['Approach','http://www.v12groupinc.com/services/approach.asp'],['Analytics and Strategy','http://www.v12groupinc.com/services/analytics_strategy.asp'],['Below the Line services','http://www.v12groupinc.com/services/below_line_services.asp'],['How to get started','http://www.v12groupinc.com/services/get_started.asp']]
var arrClients = [['Marketers','http://www.v12groupinc.com/clients/marketers.asp'],['Agencies','http://www.v12groupinc.com/clients/agencies.asp']]

var arrdataCardAboutUs = [['Vision','http://www.v12groupinc.com/about_us/vision.asp'],['History','http://www.v12groupinc.com/about_us/history.asp'],['Above/Below the Line Marketing','http://www.v12groupinc.com/about_us/above_below_marketing.asp'],['Management','http://www.v12groupinc.com/about_us/management.asp'],['News and Events','http://www.v12groupinc.com/about_us/news_events.asp'],['Careers','http://www.v12groupinc.com/about_us/careers.asp']]; 
var arrdataCardServices = [['Approach','http://www.v12groupinc.com/services/approach.asp'],['Analytics and Strategy','http://www.v12groupinc.com/services/analytics_strategy.asp'],['Below the Line services','http://www.v12groupinc.com/services/below_line_services.asp'],['How to get started','http://www.v12groupinc.com/services/get_started.asp']]
var arrdataCardClients = [['Marketers','http://www.v12groupinc.com/clients/marketers.asp'],['Agencies','http://www.v12groupinc.com/clients/agencies.asp']]


function makeChildLayer(ctl){	
	var childHTML = '';
	
	for(i=0; i < ctl.length; i++){
		childHTML += '<div id="childID_'+ i +'" class="topNavChildOff" onmouseover="overChildLink(this);" onmouseout="offChildLink(this);" onclick="document.location = \''+ ctl[i][1] +'\'"><a href="'+ ctl[i][1] +'">- '+ ctl[i][0] +'</a></div>';
	}
	
	//alert(childHTML);
	return childHTML;
}



function popWindow(url, width, height, name, scrollbars){
	if (!scrollbars) scrollbars = false;
	if (!width) width = 500;
	if (!height) height = 500;
 	var realW = (width)/2;
	var realH = (height)/2;
 	if (document.all){		
        var xMax = screen.width, yMax = screen.height;
    }else if (document.layers){       
        var xMax = screen.width, yMax = screen.height;
    }else if (document.getElementById){
		var xMax = screen.width, yMax = screen.height;
	}else{
		var xMax = 800, yMax=600;
	}
	var xOffset = ((xMax)/2) - realW, yOffset = (((yMax)/2)) - realH; 
	if (yMax==600){
		yOffset = 0;
	}	
	
	if (scrollbars) {
		var options = "directories=no,status=no,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}else{
		var options = "directories=no,status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=yes" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}
	
	if (!name) name = "default_window";
	
	popup = window.open(url,name,options);
	popup.focus();	
}


function overLeftNav(ctl){	
	var myElement = getElmtRef(ctl.id)
	myElement.className = "topNavOn";
	
}

function offLeftNav(ctl){
	var myElement = getElmtRef(ctl)
	myElement.className = "topNavOff";
	
}

function overChildLink(ctl){	
	var myElement = getElmtRef(ctl.id)
	myElement.className = "topNavChildOn";
	
}

function offChildLink(ctl){
	var myElement = getElmtRef(ctl.id)
	myElement.className = "topNavChildOff";	
}

function overTopMenu(ctl){
	var myElement = getElmtRef(ctl)
	myElement.className = "topNavOn";
	
}

function offTopMenu(ctl){
	if (document.all){
		var myElement = document.all(ctl);
	}else{
		var myElement = document.getElementById(ctl);
	}		
	myElement.className = "topMenuLink";
	
}

function displayMenu(parentId){		
	overLeftNav(parentId);	
}

function hideMenu(parentId){	
	switch(pageDirectory){
		case "about_us":
			tempOnDirectoryID = "topNav_aboutus";
			break; 
		case "press_releases":
			tempOnDirectoryID = "topNav_aboutus";
			break; 
		case "articles":
			tempOnDirectoryID = "topNav_aboutus";
			break; 
		case "services":
			tempOnDirectoryID = "topNav_services";
			break; 
		case "clients":
			tempOnDirectoryID = "topNav_clients";
			break; 
		case "contact":
			tempOnDirectoryID = "topNav_contact";
			break; 
		default:
			tempOnDirectoryID = "";
			break;			
	}
	for (i=0; i < topNavParents.length; i++){
		if (parentId.id != topNavParents[i] && topNavParents[i] != tempOnDirectoryID){
			offLeftNav(topNavParents[i])			
		}
	}		
	hideChild("topNavChild");	
}

function showChild(parentId,childId){
	
	if (is_nav6up || is_ie5up){		
		var refElmt = parentId;		

		var lyrElmt = new DynLayer("topNavChild");
		
		getElmtRef("topNavChild").innerHTML = "";
		getElmtRef("topNavChild").innerHTML = makeChildLayer(childId);	
		
		var mainTopPosition = getMainTopPosition(refElmt, lyrElmt);
		var mainLeftPosition = getMainLeftPosition(parentId);		

		lyrElmt.moveTo(mainLeftPosition, mainTopPosition);
		
		lyrElmt.show();	
	}
}

function hideChild(childId){
	if (is_nav6up || is_ie5up){		
		var lyrElmt = new DynLayer(childId);		
		lyrElmt.hide();	
	}
}

var menuTimerID;
var menuTimout = 00;
function onParent(parentId,childId){		
	if (menuTimerID) clearTimeout(menuTimerID);		
	hideMenu(parentId);	
	displayMenu(parentId);
	if (childId != ""){
		showChild(parentId,childId);
	}
}
function offParent(parentId,childId){	
	menuTimerID = setTimeout('menuTimeup()',menuTimout); 	
}

function onMenuChild(layer_ID){ clearTimeout(menuTimerID); }

function offMenuChild(layer_ID){ menuTimerID = setTimeout('menuTimeup()',menuTimout);}

function menuTimeup(){	
	var id = "";
	hideMenu(id);
}