function showProductDetail(PID, CID, RID)
{
	window.open('/popupProduct.aspx?PID=' + PID + '&CID=' + CID + '&RID=' + RID ,'_blank','location=no,toolbar=no,menubar=no,directories=no,status=no,resizable=yes,scrollbars=yes,left=100,top=100');
}

function showEmail(PID)
{
	if (window.location.href.indexOf('localhost') == -1) {
		appPath = "/";
	} else {
		appPath = '/dekko/'
	}
	window.open(appPath + 'emailFriend.aspx?PID=' + PID ,'_blank','location=no,toolbar=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=yes,left=100,top=100, width=650,height=400');
	return false
}

function showFeedback()
{
	window.open('/Feedback.aspx','_blank','location=no,toolbar=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=yes,left=100,top=100, width=650,height=400');
}

function showEmailWishlist()
{
	window.open('/emailWIshlist.aspx','_blank','location=no,toolbar=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=yes,left=100,top=100, width=650,height=400');
}

function showSofasPopup(colour, category,range,product)
{
	window.open('/popupMTOSofas.aspx?colour=' + colour + '&CID=' + category + '&RID=' + range + '&PID=' + product,'_blank','location=no,toolbar=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=yes,left=100,top=100, width=340,height=350');
}

function pngFix()
{
  // IE6 only
  if (typeof document.body.style.maxHeight != 'undefined' || !document.all) {
    return
  }
  for(var i = 0; i < document.images.length; i++) {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
      var imgID = (img.id) ? "id='" + img.id + "' " : ""
      var imgClass = (img.className) ? "class='" + img.className + "' " : ""
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
      var imgStyle = "display:inline-block;" + img.style.cssText
      if (img.align == "left") imgStyle = "float:left;" + imgStyle
      if (img.align == "right") imgStyle = "float:right;" + imgStyle
      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
      var strNewHTML = "<span " + imgID + imgClass + imgTitle
      + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
      + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
      img.outerHTML = strNewHTML
      i = i - 1
    }
  }
}

function configureMenus(menu)
{
  // when viewing Google Analytics reports leave all menus unfolded
  if (window.location.hash.indexOf('#gaso') != -1) {
	return false
  }
  // hide all submenus
  var ULs = $(menu).getElementsByTagName('UL')
  for (var i = 0; i < ULs.length; i++) {
    if (ULs[i].parentNode.id != menu) {
      if (ULs[i].parentNode.className != 'open') {
		ULs[i].style.display = 'none'
      }
    }
  }
  // add effects to submenus
  var obj = $(menu).getElementsByTagName('UL')[0].getElementsByTagName('LI')[0]
  while (obj.nextSibling) {
    if (obj.nodeType == 1) {
      // check for sub <ul>
      ULs = obj.getElementsByTagName('UL')
      if (ULs.length > 0) {
        if (ULs[0].style.display == 'none') {
		  obj.className = 'menu-closed'
        } else {
          obj.className = 'menu-open'
        }
        firstLink = obj.getElementsByTagName('A')[0]
        firstLink.href = 'javascript:void(0)'
        firstLink.onclick = function() {
          subMenu = this.parentNode.getElementsByTagName('UL')[0]
          if (subMenu.style.display == 'none') {
            new Effect.BlindDown(subMenu)
            this.parentNode.className = 'menu-open'
          } else {
            new Effect.BlindUp(subMenu)
            this.parentNode.className = 'menu-closed'
          }
        }
      }
    }
    obj = obj.nextSibling
  }
}

YAHOO.namespace("dekko.container");
/*
function panel()
{
	// Instantiate a Panel from markup
	YAHOO.dekko.container.panel1 = new YAHOO.widget.Panel('bag-summary', { width:'225px', visible:false, constraintoviewport:true, context: ['Header1_bagImage', 'bl', 'tl'], close:true, iframe:true, draggable:false, effect: {effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25} } )
	YAHOO.dekko.container.panel1.render()
	YAHOO.util.Event.addListener('Header1_BagIcon1_bagImage', 'mouseover', YAHOO.dekko.container.panel1.show, YAHOO.dekko.container.panel1, true)
	//YAHOO.util.Event.addListener("bag", "mouseout", YAHOO.dekko.container.panel1.hide, YAHOO.dekko.container.panel1, true)
}
*/

function tooltip()
{
	// HTML decode title atribute - this allows XHTML compliance to be maintained
	var tooltipText = document.getElementById('Header1_BagIcon1_bagImage').title.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
	YAHOO.dekko.container.tooltip1 = new YAHOO.widget.Tooltip("myTooltip", { context:'Header1_BagIcon1_bagImage', text:tooltipText, effect: {effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} } )
}

function bookmarksite(title,url)
{
	// firefox
	if (window.sidebar) {
		alert('Use CTRL + D to add shopdekko.com to your bookmarks')
	// opera
	} else if (window.opera && window.print) {
		var elem = document.createElement('a')
		elem.setAttribute('href',url)
		elem.setAttribute('title',title)
		elem.setAttribute('rel','sidebar')
		elem.click()
	// ie
	} else if (document.all) {
		window.external.AddFavorite(url, title)
	}
}

function displaySWF()
{
	var param, key, value, parameters
	var divs = document.getElementsByTagName('DIV')
	var count = 0
	var swfs = []
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].title.indexOf('swf') != -1) {
			parts = divs[i].title.split(';')
			parameters = { 'id': divs[i].id, 'class': divs[i].className }
			for (var j = 0; j < parts.length; j++) {
				param = parts[j].split(':', 2)
				key = param[0].replace(/ /g, '')
				value = param[1].replace(/ /g, '')
				parameters[key] = value
			}
			swfs[count] = parameters
			count++
		}
	}
	// emdeb SWFs in separate for loop as if used in above for loop numbers of divs change as swfs are embedded in Firefox
	for (var i = 0; i < swfs.length; i++) {
		swfobject.embedSWF((window.location.href.indexOf('localhost') == -1 ? '' : 'http://localhost/dekko') + '/imagesContentManaged/' + swfs[i]['swf'], swfs[i]['id'], swfs[i]['width'], swfs[i]['height'], '8', null, null, {wmode: 'transparent'}, {styleclass: swfs[i]['class']})
	}
}

function preloadButtons()
{
	var parts, pathCount, file, path, imgOver
	var buttons = document.getElementsByTagName('INPUT')
	for (var i = 0; i < buttons.length; i++) {
		if (buttons[i].type == 'image' && buttons[i].src.indexOf('button-') != -1) {
			parts = buttons[i].src.split('/')
			pathCount = parts.length - 1
			file = parts[pathCount]
			path = ''
			for (j = 0; j < pathCount; j++) {
				path += parts[j] + '/'
			}
			imgOver = path + file.replace(/\.gif$/, '-on.gif')
			img = new Image()
			img.src = imgOver
			
		}
	}
}

function initDOM()
{
	pngFix()
	configureMenus('leftnav')
	preloadButtons()
	displaySWF()
	tooltip()
	Shadowbox.init({ overlayOpacity : 0.75, viewportPadding : 20 })
}

// this function is called by globe.swf
function chooseCountry()
{
	if (window.location.href.indexOf('localhost') == -1) {
		appPath = "/";
	} else {
		appPath = '/dekko/'
	}
	Shadowbox.open({ width: 300, height: 260, type: 'iframe', content: appPath + 'ChooseCountry.aspx' })
}

YAHOO.util.Event.onDOMReady(initDOM)