﻿function toggleDivDisplay(divId) {
	if (document.getElementById(divId).style.display == "none")
		document.getElementById(divId).style.display = "block";
	else
		document.getElementById(divId).style.display = "none";
}

function showDiv(divId) {
	document.getElementById(divId).style.display = "block";
}

function hideDiv(divId) {
	document.getElementById(divId).style.display = "none";
}

var popupWindow = false; 
function openPopup(url,w,h) {
	x = screen.width/2-w/2;
	y = screen.height/2-h/2;
	if (popupWindow) popupWindow.close();
    popupWindow=window.open(url,'ny','toolbar=no,copyhistory=no,location=no,' + 'directories=no,status=no,menubar=no,scrollbars=no,' +'resizable=no,width=' + w + ',height=' + h + ',top=' + y +',left=' + x);
}

function openPopupPay(url,w,h) {
	x = screen.width/2-w/2;
	y = screen.height/2-h/2;
	if (popupWindow) popupWindow.close();
    popupWindow=window.open(url,'ny','toolbar=no,copyhistory=no,location=yes,' + 'directories=no,status=yes,menubar=no,scrollbars=yes,' +'resizable=no,width=' + w + ',height=' + h + ',top=' + y +',left=' + x);
}

function toggleImage(element) {
	curImg = document.getElementById(element).src
	if (curImg.match("_on.") == "_on.") {
		document.getElementById(element).src = curImg.replace(/_on./i,"_off.")
	}
	else {
		document.getElementById(element).src = curImg.replace(/_off./i,"_on.")
	}
}
function toggleClass(element) {
	curClass = document.getElementById(element).className
	if (curClass == "Off") {
		//document.getElementById(element).src = curImg.replace(/_on./i,"_off.")
		newClass = 'On'
	}
	else {
		//document.getElementById(element).src = curImg.replace(/_off./i,"_on.")
		newClass = 'Off'
	}
	document.getElementById(element).className = newClass 


}

function product_preview(img) {
	document.getElementById('SlideShow').src=img;
	document.getElementById('popupImageLink').href=img.replace(/\/b\//,"/c/");
	Lightbox.prototype.updateImageList();
}
function getUpdate(type,parameter1,parameter2,pid) { //flashrotator status function
  if (type == 'item' && pid == 'productrotator') {
	document.getElementById("imgNr").innerHTML = parameter1+1;
	document.getElementById("popupTextLink").onclick = function() { doImageClick(parameter1+1) };

  }
}

function hideSplash(val) {

	elementBg = document.getElementById("SplashBg").style;
	element = document.getElementById("Splash").style;
	
	incre = 6
    if (val > 0) {
		element.filter = 'alpha(opacity='+val+')';
		element.opacity = val/100;
		elementBg.filter = 'alpha(opacity='+val+')';
		elementBg.opacity = val/100;
		timerID = setTimeout('hideSplash('+(val-incre)+')', 35);	
	}
	if (val <= 0) {
		element.filter = 'alpha(opacity=0)'; // set opacity = 0
		element.opacity = 0;
		elementBg.filter = 'alpha(opacity=0)';
		elementBg.opacity = 0; 

		element.display='none';  // reset values for next use
		element.filter = 'alpha(opacity=85)';
		element.opacity = 0.85;
		elementBg.display='none';  // reset values for next use
		elementBg.filter = 'alpha(opacity=100)';
		elementBg.opacity = 1;		
	}		
}

$(document).ready(function() {


  var anchors = document.getElementsByTagName('a');
  nPlayer = 0;
  
  for (var i=0; i<anchors.length; i++){
	var anchor = anchors[i];
	var relAttribute = String(anchor.getAttribute('rel'));

	if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('mp3'))){
		anchor.setAttribute('id','nPlay'+i)			
		anchor.onclick = Function("nPlay('"+anchor.getAttribute('href')+"',this.id); return false;");
		anchor.onfocus = function(){this.blur();}; 
		nPlayer = 1
	}
	if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('mouseover'))){

		anchor.firstChild.onmouseover = Function("this.src=this.src.replace(/off\\./ig,\"on\\.\")");
		anchor.firstChild.onmouseout = Function("this.src=this.src.replace(/on\\./ig,\"off\\.\")");
	
} 
  }
  
  if (nPlayer == 1) {

	np = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="1" height="1" id="niftyPlayer1">'
	np += '<param name=movie value="/includes/mp3player/niftyplayer.swf">'
	np += '<param name=quality value=high>'
	np += '<param name=bgcolor value=#FFFFFF>'
	np += '<param name="wmode" value="opaque">'
	np += '<embed src="/includes/mp3player/niftyplayer.swf" quality="high" bgcolor=#FFFFFF width="1" height="1" name="niftyPlayer1" wmode="opaque" swLiveConnect="true" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>'
	np += '</object>'
	jQuery('body').append(np);

  }
});

productImages_activeBtn = '';
function productImages(filename,btn,action) {

   if (action >= 2 && btn!= productImages_activeBtn) {
	if (action == 2) { clearTimeout(RotateTimer) }
	curSrc = $('#productImage').attr('src')
	curPath = curSrc.substring(0,curSrc.lastIndexOf("/")+1)
	curImg = curSrc.replace(curPath,"")
	
	$('#productImage').attr('src',curPath+filename);
	fadeIn('#productImage',400)
	
	$('#productImage').parent().attr('href',curPath.replace(/b/,"c")+filename);
	Shadowbox.setup()
   
	if (productImages_activeBtn != '') {
		classname = $('#'+productImages_activeBtn).attr('class')
		if (classname.indexOf(" ") > 0) { classname = classname.substring(0,classname.indexOf(" ")) }
		$('#'+productImages_activeBtn).removeClass(classname+'On')
	}
	if (action == 3) {
	  classname = $('#'+btn).attr('class')
	  $('#'+btn).addClass(classname+'On')
	}
	productImages_activeBtn = btn
	}

  if (action == 1 && btn!= productImages_activeBtn) {
	classname = $('#'+btn).attr('class')
	$('#'+btn).addClass(classname+'On')
  }

  if (action == 0 && btn!= productImages_activeBtn) {
	classname = $('#'+btn).attr('class')
	if (classname.indexOf(" ") > 0) { classname = classname.substring(0,classname.indexOf(" ")) }
	$('#'+btn).removeClass(classname+'On')
  }
}

function productImageRotate(img,iImages) {
	if (img >= iImages) { img = 0 }
	img = (img+1)

	fil = $('#pil'+img).attr('href')
	fil = fil.substring(fil.lastIndexOf("/")+1)
	productImages(fil,'pib'+img,3) 
	
	RotateTimer = setTimeout('productImageRotate('+img+','+iImages+')', 6000);	
	
}

function fadeIn(el,t) {
	$(el).css('display','none');
	$(el).fadeIn(t);
}


