/**
 HP - Ink
 IN / EN
 created: 3/3/2009
 updated: 9/1/2009
**/

// static tracking code
//var s_hp_apj_testPage = true; // remove after testing

/* start code vars */
/* top menu NOTE:zero-based */
var TAB1 = 1;
var TAB2 = 2;
var TAB3 = 3;
var TAB4 = 4;
var TAB5 = 5;
var TAB6 = 6;
var tabLinks = [];
var tabPanels = [];
var totalTabs = 6;
var tabLinkOmnis = ['', 'why hp original', 'products', 'hp promotion', 'link:find my cartridge', 'link:register your hp printer', 'link:shop now'];
var tabDDTab1Omnis = ['', 'about the reliability study'];
var tabDDTab2Omnis = ['', 'standard cartridges', 'value packs', 'specialty cartridges', 'simple black cartridges'];
var tabDDTab5Omnis = ['','link:register your hp printer', 'link:register your hp cartridge'];
var overTopImgs = ['', 'images/global/btn_whyOriginal_b.jpg', 'images/global/btn_product_b.jpg', 'images/global/btn_perfBonus_b.jpg', 'images/global/btn_findMyCart_b.jpg', 'images/global/btn_registerhp_b.jpg', 'images/global/btn_shopNow_b.jpg'];
/* product menu */
var productTabs = [];
var totalProducts = 3; // footer
var popDowners = [];
var productPops = [];
var lastPopUp = null;
var prodHrefs = ['product1.html', 'product2.html', 'product3.html', 'product4.html'];
var productPopsOmnis = ['standard cartridges', 'value packs', 'specialty cartridges'];
/* right banners */
//var rsBanners = ['inkpromotion.html', 'http://h20423.www2.hp.com/program/suresupply/in/en/sure_get.asp#dac', 'http://h20431.www2.hp.com/support/contactcenters/in/en/ocs/south.html', 'shop.html', 'register.html'];
var rsBannersOmnis = ['click:hp promotion','link:dial a cartridge','link:hp original cartridge stores','link:buy online','link:win 28000 prizes'];
/* others */
var browserInfo = {};

document.write('<script'+' language="'+'javascript'+'" src="scripts/kukyo_sou.js">'+'</'+'script>');
document.write('<script'+' language="'+'javascript'+'" src="scripts/Tween.js">'+'</'+'script>');
document.write('<script'+' language="'+'javascript'+'" src="scripts/jsmt.js">'+'</'+'script>');
// remove after debug
document.write('<script'+' language="'+'javascript'+'" src="scripts/tracker.js">'+'</'+'script>');

doJumpTracking();

function initInk()
{
	initTabs();
	initTopTabs();
	initProductTabs();
	browserInfo = getBrowser();
	initKukyoSou();
	preloadImages();
	if (useValueCalculator) {
		showcalculator();
	}
}

/* products etc */
function initTabs()
{
	popDowners = [];
	productPops = [];
	for (var i=0; i<totalProducts; i++)
	{
		productPops.push({iu:false});
	}
	for (var i=0; i<=totalTabs; i++)
	{
		popDowners.push({isu:false, isd:false});
	}
}

function initTopTabs()
{
	var child;
	tabPanels[0] =
	tabPanels[1] =
	tabPanels[2] =
	tabPanels[3] = 
	tabPanels[4] = 
	tabPanels[5] = 
	tabPanels[6] = false;
	tabLinks[0] = 
	tabLinks[1] = 
	tabLinks[2] = 
	tabLinks[3] = 
	tabLinks[4] = 
	tabLinks[5] = 
	tabLinks[6] = null;
	var tabLink1 = document.getElementById("tabLink1");
	var tabLink2 = document.getElementById("tabLink2");
	var tabLink3 = document.getElementById("tabLink3");
	var tabLink4 = document.getElementById("tabLink4");
	var tabLink5 = document.getElementById("tabLink5");
	var tabLink6 = document.getElementById("tabLink6");
	tabLink1.idx = 1;
	tabLink2.idx = 2;
	tabLink3.idx = 3;
	tabLink4.idx = 4;
	tabLink5.idx = 5;
	tabLink6.idx = 6;
	tabLink1.childId = 'whyOIDropDrop';
	tabLink2.childId = 'productsDropDrop';
	tabLink3.childId = '';
	tabLink4.childId = '';
	tabLink5.childId = 'registerDropDrop';
	tabLink6.childId = '';
	tabLink1.onmouseover = showTabLinkParent;
	tabLink2.onmouseover = showTabLinkParent;
	tabLink3.onmouseover = showTabLinkParent;
	tabLink4.onmouseover = showTabLinkParent;
	tabLink5.onmouseover = showTabLinkParent;
	tabLink6.onmouseover = showTabLinkParent;
	// onmouseout
	tabLink1.onmouseout = delayHideTabLink1;
	tabLink2.onmouseout = delayHideTabLink2;
	tabLink3.onmouseout = restoreImageSwap;
	tabLink4.onmouseout = restoreImageSwap;
	tabLink5.onmouseout = delayHideTabLink5;
	tabLink6.onmouseout = restoreImageSwap;
	tabLink1.onmousedown = 
	tabLink2.onmousedown = 
	tabLink3.onmousedown = 
	tabLink4.onmousedown = 
	tabLink5.onmousedown = 
	tabLink6.onmousedown = trackTabLink;
	
	// whyOI dropdown
	child = document.getElementById(tabLink1.childId);
	child.onmouseout = hideTabLink;
	child.onmouseover = setTabOver;
	child.childId = child.id;
	tabLinks[1] = child;
	var whyOIDropDrop = document.getElementById("whyOIDropDrop");
	whyOIDropDrop.onmouseout = delayHideTabLink1;
	whyOIDropDrop.idx = 1
	var ddTab1_1 = document.getElementById("ddTab1_1");
	ddTab1_1.onmousedown = trackDDTab1;
	// products dropdown
	child = document.getElementById(tabLink2.childId);
	child.onmouseout = hideTabLink;
	child.onmouseover = setTabOver;
	child.childId = child.id;
	tabLinks[2] = child;
	var productsDropDrop = document.getElementById("productsDropDrop");
	productsDropDrop.onmouseout = delayHideTabLink2;
	productsDropDrop.idx = 2;
	var ddTab2_1 = document.getElementById("ddTab2_1");
	var ddTab2_2 = document.getElementById("ddTab2_2");
	var ddTab2_3 = document.getElementById("ddTab2_3");
	var ddTab2_4 = document.getElementById("ddTab2_4");
	ddTab2_1.onmousedown = trackDDTab2;
	ddTab2_2.onmousedown = trackDDTab2;
	ddTab2_3.onmousedown = trackDDTab2;
	ddTab2_4.onmousedown = trackDDTab2;
	// register dropdown
	child = document.getElementById(tabLink5.childId);
	child.onmouseout = hideTabLink;
	child.onmouseover = setTabOver;
	child.childId = child.id;
	tabLinks[5] = child;
	var registerDropDrop = document.getElementById("registerDropDrop");
	registerDropDrop.onmouseout = delayHideTabLink5;
	registerDropDrop.idx = 5;
	var ddTab5_1 = document.getElementById("ddTab5_1");
	var ddTab5_2 = document.getElementById("ddTab5_2");
	ddTab5_1.onmousedown = trackDDTab5;
	ddTab5_2.onmousedown = trackDDTab5;
}

function initProductTabs()
{
//	alert('initProductTabs');
	var i = 1;
	var prodBtn;
	var popupFoot;
	for (i; i<=totalProducts; i++)
	{
		prodBtn = document.getElementById('btmPopBtn'+i);
		popupFootLyr = document.getElementById('popupFootLyr'+i);
		popupFoot = document.getElementById('popupFoot'+i);
		popupFoot.idx = prodBtn.idx = i;
//		prodBtn.href = prodHrefs[i-1];
		prodBtn.onmouseover = showPopupFoot;
		prodBtn.onmouseout = hidePopupFoot;
		popupFoot.style.display = 'block';
		popupFootLyr.style.visibility = "hidden";
//		popupFoot.onmouseout = hidePopupFoot;
	}
}


function trackTabLink()
{
	var linknam = tabLinkOmnis[this.idx];
	gmTrackLink(linknam, 'home');
}

function trackDDTab1()
{
	var linknam = tabDDTab1Omnis[this.id.charAt(7)];
	gmTrackLink(linknam, 'home');
}
function trackDDTab2()
{
	var linknam = tabDDTab2Omnis[this.id.charAt(7)];
	gmTrackLink(linknam, 'home');
}
function trackDDTab5()
{
	var linknam = tabDDTab5Omnis[this.id.charAt(7)];
	gmTrackLink(linknam, 'home');
}

function showPopupFoot()
{
	removePopList(this.idx);
	var popupFoot = document.getElementById('popupFootLyr'+this.idx);
	popupFoot.style.visibility = "visible";
	popupFoot.style.top = "100px";
	var np = ns ? -60 : -66;
	var nq = ns ? -40 : -10;
	popupAnim('popupFootLyr',this.idx, {xpos:nq, ypos:np, timeout:.5, doComplete:true});
//	alert('np: '+ np);
//	popDowners[this.idx-1].isu = true;
//	if (bTmp[this.idx-1]) bTmp[this.idx-1].removeListener();
	lastPopUp = {idx:this.idx};
	productPops[this.idx-1].iu = true;
//	showDebug('showPopupFoot: '+this.idx)
}

/*do single hide*/
function hidePopupFoot()
{
	removePopList(this.idx);
//	showDebug('hidePopupFoot1a: '+[this.idx, popDowners[this.idx-1].isd ]);
	var popupFoot;
	popupFoot = document.getElementById('popupFootLyr'+this.idx);
//	popDowners[this.idx-1].isu = false;
//	popdownAnim('popupFootLyr',this.idx, {xpos:parseInt(popupFoot.style.top), ypos:0, doComplete:true});
//	if (aTmp[this.idx-1]) aTmp[this.idx-1].removeListener();
	var np = ns ? 0 : -10;
	popdownAnim('popupFootLyr',this.idx, {xpos:parseInt(popupFoot.style.top), ypos:np, timeout:.5, doHide:true, doComplete:true});
	productPops[this.idx-1].iu = true;
}

/*do multi hide*/
function hidePopupFoot2()
{
	var i = 1;
	var n = this.idx;
	var popupFoot;
	popupFoot = document.getElementById('popupFootLyr'+this.idx);
//	popdownAnim('popupFootLyr',n, {xpos:0, ypos:100, doComplete:true});
	for (i; i<=totalPopups; i++)
	{
		if (i!=n)
		{
			if (productPops[i-1].iu)
			{
				popdownAnim('popupFootLyr', i, {xpos:0, ypos:100, doComplete:true});
			}
			//popupFoot.style.visibility = "hidden";
		}
	}
}

function showTabLinkParent()
{
//	alert('showTabLinkParent: '+this.idx);
	MM_swapImage('tpImg'+this.idx,'',overTopImgs[this.idx],1);
	if (!this.childId) return;
//window.status = ('showTabLinkParent: '+ [this.id, this.idx]);
	showTabLink1(this.childId, this.idx);
	tabPanels[this.idx] = true;
//	alert('overTopImgs: '+overTopImgs[this.idx-1]);
//	window.status = 'overTopImgs: '+overTopImgs[this.idx-1];
}

function showTabLink1(s, n)
{
	window.status = 'showTabLink1: '+ s;
	var child = document.getElementById(s);
	if (tabPanels[n]) return;
	showTabAnim(s, n, {xpos:-10, ypos:54, timeout:.5});
	child.style.visibility = 'visible';
	tabPanels[n] = true;
}

function setTabOver()
{
	tabPanels[this.idx] = true;
}

function restoreImageSwap()
{
	MM_swapImgRestore();
}

function delayHideTabLink1()
{
//	alert('delayHideTabLink3: '+ tabPanels[5-1]);
	MM_swapImgRestore();
	if (!tabPanels[TAB1]) return;
	setTimeout(function(){hideTabLink1()}, 100);
	tabPanels[TAB1] = false;
}

function delayHideTabLink2()
{
//	window.status = ('delayHideTabLink');
//	if (tabPanels[this.idx-1]) return;
//	alert('delayHideTabLink: '+ tabPanels[5-1]);
	MM_swapImgRestore();
	if (!tabPanels[TAB2]) return;
	setTimeout(function(){hideTabLink2()}, 100);
	tabPanels[TAB2] = false;
}

function delayHideTabLink5()
{
//	alert('delayHideTabLink4: '+ tabPanels[4-1]);
	MM_swapImgRestore();
	if (!tabPanels[TAB5]) return;
	setTimeout(function(){hideTabLink5()}, 100);
	tabPanels[TAB5] = false;
}

function hideTabLink()
{
//	window.status = 'hideTabLink';
	var s = this.childId;
	var t = document.getElementById(this.id);
//	alert('hideTabLink: '+s);
//	alert('hideTabLink.visibility: '+t.style.visibility);
	hideTabAnim(this.id, this.idx, {xpos:parseInt(t.style.top), ypos:-56, timeout:.2, doComplete:true});
//	t.style.visibility = 'hidden';
}

/* whyOIDropDrop */
function hideTabLink1(c, n)
{
	if (tabPanels[TAB1]) return;
	hideTabAnim('whyOIDropDrop', TAB1, {xpos:56, ypos:0, timeout:.2, doComplete:true});
	tabPanels[TAB1] = true;
}

/* products */
function hideTabLink2()
{
	if (tabPanels[TAB2]) return;
	hideTabAnim('productsDropDrop', TAB2, {xpos:56, ypos:-10, timeout:.2, doComplete:true});
	tabPanels[TAB2] = true;
}

/* register */
function hideTabLink5()
{
	if (tabPanels[TAB5]) return;
	hideTabAnim('registerDropDrop', TAB5, {xpos:56, ypos:-10, timeout:.2, doComplete:true});
	tabPanels[TAB5] = true;
}

function gotoProduct()
{

}

function popupProduct(n, t)
{
	if (browserInfo.msie)
	{
		var s = (typeof(n)=='string') ? n : this.childId;
	} else {
		var s = (typeof(n)=='string') ? n : n.currentTarget.id;
	}
	var child = document.getElementById(s);
	gmTrackLink(productPopsOmnis[n-1], 'products');
//	s_hp_fixObjectID(s_objectID);
}

/* MM scripts */
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_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_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); return x;
}

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 preloadImages()
{
	MM_preloadImages('images/global/btn_standardCart_b.jpg','images/global/btn_valuePacks_b.jpg','images/global/btn_specialtyCart_b.jpg','images/global/btn_shopNow_b.jpg','images/global/btn_whyOriginal_b.jpg','images/global/btn_product_b.jpg','images/global/btn_perfBonus_b.jpg','images/global/btn_findMyCart_b.jpg');
}


function doJumpTracking()
{
	var u = document.location.toString().split('?');
	if (u[1])
	{
		u = u[1].split('jumpid=');
		if (u[1])
		gmSetCookie('jumpid', u[1]);
	}
}

function getJumpId()
{
	var tmp = gmGetCookie('jumpid');
	if (tmp) {
		return tmp;
	} else {
		return '';
	}
}

function gmSetCookie(name, str)
{
	var today = new Date();
	today.setTime( today.getTime() );
	expires = today.getYear() * 1000 * 60 * 60 * 24;
	var exp = new Date( today.getTime() + expires );
	document.cookie = name+'='+ str + "; path=/; expires=" + exp.toGMTString();
}

function gmGetCookie(name)
{
	var results = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

