Page.Display = function(){}
Page.Display.Parameters = {
	LAST_SIZE : 0,
	PRODUCT_CELL_ID : 0,
	CLIENT_BROWSER_ID : 0,
	IFRAME_SUPPORT : false,
	ID_ROLLOVER_MENU : null
}

function JS_Initialize(dbg, brs, ifs, pc) {
	Page.Display.Parameters.IFRAME_SUPPORT = (ifs == 1);
	Page.Display.Parameters.DEBUG_MODE = (dbg == 1);
	Page.Display.Parameters.CLIENT_BROWSER_ID = brs;
	Page.Display.Parameters.PRODUCT_CELL_ID = pc;

	switch (Page.Display.Parameters.CLIENT_BROWSER_ID) {
		case 1:
			Page.Display.Parameters.ID_ROLLOVER_MENU = window.setInterval(Page.Display.RolloverMenu, 10);
			window.setInterval('Page.Display.AutoFontSizeForIE()', 200);
			break;

		case 2:
			window.setInterval('Page.Display.AutoFontSizeForFF()', 200);
			break;

		default:
			break;
	}
	AttachEvent(window,'load',Page.Display.AutoWidthProductCell);
	AttachEvent(window,'resize',Page.Display.AutoWidthProductCell);
}


Page.Display.RolloverMenu = function() {
	window.clearInterval(Page.Display.Parameters.ID_ROLLOVER_MENU);
	var initialized = Page.Display.RolloverMenu.Initialize();
	if (!initialized) {
		Page.Display.Parameters.ID_ROLLOVER_MENU = window.setInterval(Page.Display.RolloverMenu, 10);
	}
}

Page.Display.RolloverMenu.Initialize = function() {
	var initialized = false;
	if (document.all && $('leftNav')){
		var root = $('leftNav');
		var nav = null;
		var node = null;
		if (Page.Display.Parameters.IFRAME_SUPPORT) {
			AttachEvent(root,'mouseover', Page.Display.RolloverMenu.ApplyIFrame);
		}
		AttachEvent(root, 'mouseover', Page.Display.RolloverMenu.MouseOver);
		AttachEvent(root, 'mouseout', Page.Display.RolloverMenu.MouseOut);		
		initialized = true;
	}
	return initialized;
}

Page.Display.RolloverMenu.ApplyIFrame = function() {	
	var p = event.srcElement.parentNode;
	if (p.childNodes.length == 3 && p.childNodes[2].childNodes.length > 0) {	
		var f = p.childNodes[2];	
		var c = f.childNodes[0];	
		if (c.style.width == '0px' && c.style.height == '0px') {		
			var menuWidth = f.offsetWidth - 0;		
			var menuHeight = f.offsetHeight - 0;
			if (menuWidth != 'NaN' && menuHeight != 'NaN') {			
				c.style.width = menuWidth;
				c.style.height = menuHeight;
			}
		}
	}
}

Page.Display.RolloverMenu.MouseOver = function() {
	var p = null;
	var c = null;
	if (event.srcElement.nodeName == 'IMG') {
		p = event.srcElement.parentNode.parentNode.parentNode
		
	} else if (event.srcElement.nodeName == 'UL') {
		p = event.srcElement.parentNode.parentNode
		
	} else {
		p = event.srcElement.parentNode;
	}
	p = (p.childNodes.length == 2) ? p.parentNode.parentNode : p;
	if (c = p.childNodes[2]) {
		c.className += ' over';
	}	
}

Page.Display.RolloverMenu.MouseOut = function() {
	var p = null;
	var c = null;
	if (event.srcElement.nodeName == 'IMG') {
		p = event.srcElement.parentNode.parentNode.parentNode;
		
	} else if (event.srcElement.nodeName == 'UL') {
		p = event.srcElement.parentNode.parentNode;
		
	} else {
		p = event.srcElement.parentNode;
	}	
	p = (p.childNodes.length == 2) ? p.parentNode.parentNode : p;		
	if (c = p.childNodes[2]) {
		c.className = c.className.replace(' over', '');
	}	
}

function SetStyle(id,css,type) {
	var o;
	if (o = document.getElementById(id)) {
		switch (type){
			case 0:
				o.className = css;
				break;

			case 1:
				o.className += " "+css;
				break;

			default:
				break;
		}
	}
}

function ClearStyle(id,css,type) {
	var o;
	if (o = document.getElementById(id)){
		switch (type) {
			case 0:
				o.className = "";
				break;

			case 1:
				o.className = o.className.replace(" "+css,"");
				break;

			default:
				break;
		}
	}
}

Page.Display.AutoFontSizeForFF = function() {
	var dBody = document.defaultView.getComputedStyle(document.body,null);
	var dSize = dBody.getPropertyValue("font-size");
	dSize = parseInt(dSize.replace("/[^\d]/",""));
	if (dSize == Page.Display.Parameters.LAST_SIZE){return;}

	if (dSize > 16){
		if (dSize < 24){
			SetStyle("TopNavigation","FontSizeLarger",0);
			SetStyle("leftNav","FontSizeLarger",0);
			SetStyle("Search-6","FontSizeLarger",0);
			SetStyle("centerArea","FontSizeLarger",0);
			SetStyle("prdTopNav","prdTopNavSize1",0);

		}else{
			SetStyle("TopNavigation","FontSizeLargest",0);
			SetStyle("leftNav","FontSizeLargest",0);
			SetStyle("Search-6","FontSizeLargest",0)
			SetStyle("centerArea","FontSizeLargest",0);
			SetStyle("prdTopNav","prdTopNavSize1",0);
		}
	}else{
		ClearStyle("TopNavigation","",0);
		ClearStyle("leftNav","",0);
		ClearStyle("Search-6","",0);
		ClearStyle("centerArea","",0);
		ClearStyle("prdTopNav","",0);
	}
	var bfw;
	if (bfw = document.getElementById("BigFontWarring")){
		if (dSize > 24){
			bfw.style.display = "block";
		}else{
			bfw.style.display = "none";
		}
	}
	Page.Display.Parameters.LAST_SIZE = dSize;
	Page.Display.AutoWidthProductCell();
}

Page.Display.AutoFontSizeForIE = function() {
	if (!window.readyState == "complete"){return;}
	if (!document.getElementById("IEFontCheck")){return;}
	var dSize = document.getElementById("IEFontCheck").offsetWidth;
	var action = 1;
	if (dSize == Page.Display.Parameters.LAST_SIZE){return;}

	if (dSize <= 8){
		action = 1;
	}else if(dSize <= 10){
		action = 2;
	}
	else{
		action = 3;
	}
	SetActivedCSS(action);
	Page.Display.Parameters.LAST_SIZE = dSize;
	Page.Display.AutoWidthProductCell();
}

Page.Display.AutoWidthProductCell = function(){
	switch (Page.Display.Parameters.PRODUCT_CELL_ID){
		case 1: //Homepage Store Except DVD Store
			Page.Display.AutoWidthProductCellGeneral();
			break;

		case 2: //DVD Store
			Page.Display.AutoWidthProductCellDVD();
			break;

		default:
			break;
	}
}

Page.Display.AutoWidthProductCellGeneral = function() {
	if (!document.getElementById("centerArea")){return;}
	if (!document.getElementById("HomepagePrd")){return;}
	var w = parseInt(document.getElementById("centerArea").offsetWidth);
	var ic = document.getElementById("HomepagePrd").className.replace(/[^\d]/ig,'') - 0;
	w = (w < 464) ? 464:w;
	var cc = Math.floor(w / 233);
	var mx = (ic < 4) ? ic:4;
	cc = (cc > mx) ? mx:cc;
	var pd = ((w - (233 * cc)) / (cc*2)) + 'px';
	var hps;
	for (var i = 1; i <= ic; ++i) {
		if (hps = document.getElementById('Section' + i)) {
			hps.style.posTop = '0px';
			hps.style.paddingLeft = pd;
			if ((i % cc) == 0) {
				hps.className = "SectionRt";
				hps.style.paddingRight = '0px';
			} else {
				hps.className = "Section";
				hps.style.paddingRight = pd;
			}
		}
	}
}

Page.Display.AutoWidthProductCellDVD = function() {
	if (!document.getElementById("centerArea")){return;}
	var ic = [0, 0, 0];
	var itn = ['ne','ns','cs'];
	var hdvd = false;
	var o,tic = 0;
	if (o = document.getElementById("neDVDPrd")){
		ic[0] = o.className.replace(/[^\d]/ig,'') - 0;
		hdvd = true;
		o = null;
	}
	if (o = document.getElementById("nsDVDPrd")){
		ic[1] = o.className.replace(/[^\d]/ig,'') - 0;
		hdvd = true;
		o = null;
	}
	if (o = document.getElementById("csDVDPrd")){
		ic[2] = o.className.replace(/[^\d]/ig,'') - 0;
		hdvd = true;
		o = null;
	}
	if (!hdvd){return;}
	for (var i = 0; i < ic.length; ++i) {
		tic = (tic < ic[i]) ? ic[i]:tic;
	}

	var w = parseInt(document.getElementById("centerArea").offsetWidth);
	w = (w < 464) ? 464:w;
	var cc = Math.floor(w / 233);
	var mx = (tic < 4) ? ic:4;
	cc = (cc > mx) ? mx:cc;
	var pd = ((w - (233 * cc)) / (cc*2)) + 'px';

	var hps;
	for (var j = 0; j < ic.length; ++j) {
		for (var i = 1; i <= ic[j]; ++i) {
			if (hps = document.getElementById('Section' + itn[j] + i)) {
				hps.style.display = '';
				hps.style.posTop = '0px';
				hps.style.paddingLeft = pd;
				if ((i % cc) == 0) {
					hps.className = "SectionRt";
					hps.style.paddingRight = '0px';
				} else {
					hps.className = "Section";
					hps.style.paddingRight = pd;
				}
			}
		}
		if (j == 0 && cc == 3 && hps){ hps.style.display = 'none';}
	}
}