

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_findObjMenu(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_findObjMenu(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_findObjMenu(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
   //alert('swap image');
}

function MM_showHideMenuLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideMenuLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }   

}

// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
function correctPNG() 
   {
       var pngImages = document.getElementsByName("pngimage");
       
       for(var i=0; i< pngImages.length; i++){
      
	      var img = pngImages[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
		     
	      }
      }
   }

function SetLogin(loginname)
{
    var mf = GetMainFormName();
    if (mf==null) return;
    var login = GetElementID("hidden_login",mf)
    if (login!= null)
    {    
        document.forms[mf].elements[login].value = loginname;        
    }
}


function ScrollWindowToShoppingCart(){
       window.scrollTo(0, 0); 
   
}

function ToggleDropDownsOnIE6(_show) {
   if (IsBrowserIE6()) {
      var obj=document.getElementById('BROWSEBY_DROPDOWNS');
      if (obj!=null) {
              if (_show) {
                 obj.style.display="";
              }
              else {
                obj.style.display="none";
              }
      
      }
   
   }


}

function IsBrowserIE6() {
  if (navigator.appName=='Microsoft Internet Explorer') {
      if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
         return true;
      }
  }
  return false;

}

function facebook(subject) {
	u=location.href;
	if ( typeof(subject) != 'undefined' ){
	    u=location.href + "#videotab";
	    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(subject),'sharer','toolbar=0,status=0,width=626,height=436');
	}    
    else
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}


function CreateTransparentControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value=' + URL + '>'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
  
  objectTag = objectTag + '<param name="wmode" value="transparent" />'
				
  objectTag = objectTag + '<embed wmode="transparent" src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#000000" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
  objectTag = objectTag + "</object>";  
  d.innerHTML = objectTag;

}

function SendVideoEmail(emailSubject){
    _EmailFriendBubble_Class.ProductCode = "";
    _EmailFriendBubble_Class.TopicCode = "";
    _EmailFriendBubble_Class.IsStaticTemplate = true;
    _EmailFriendBubble_Class.TopicEmailTemplate = "TellAFriendVideo.xml";
    _EmailFriendBubble_Class.TellAFriendPageURL = document.location.href + "#videotab";
    _EmailFriendBubble_Class.ShowBubble(emailSubject);
    ToggleQtyOnIE6(false);
    HideSampleShopCrtBubble();
    /*
    //reinitialize variable for 
    _EmailFriendBubble_Class.IsStaticTemplate = false;
    _EmailFriendBubble_Class.TellAFriendPageURL = "";
    _EmailFriendBubble_Class.TopicEmailTemplate = "Topic_TellAFriend.xml";*/
}      

function CreateVideoPlayerControl(DivID, WIDTH, HEIGHT, URL, VideoType){  
  
  if ( VideoType == '' || VideoType =='youtube' ){
      var d = document.getElementById(DivID);
      var objectTag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="' + WIDTH + '" height="' + HEIGHT +'" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
      objectTag = objectTag +  '<param name="wmode" value="opaque">' ;
      objectTag = objectTag + '<param name="allowScriptAccess" value="always">';
      objectTag = objectTag + '<param name="allowfullscreen" value="true"></param>';
      objectTag = objectTag + '<param name="movie" value=' + URL + '>'  
    				
      objectTag = objectTag + '<embed allowfullscreen="true" wmode="opaque" src="' + URL + '" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
      objectTag = objectTag + "</object>";
      d.innerHTML = objectTag;
  } else {
    //alert('implement the other player');
  }
       
  
}

/*
* The code below is taken from Google Code library. This can be used for callings functions when the document has finished loading. 
*/
(function(){

    var DomReady = window.DomReady = {};

	// Everything that has to do with properly supporting our document ready event. Brought over from the most awesome jQuery. 

    var userAgent = navigator.userAgent.toLowerCase();

    // Figure out what browser is being used
    var browser = {
    	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
    	safari: /webkit/.test(userAgent),
    	opera: /opera/.test(userAgent),
    	msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),
    	mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))
    };    

	var readyBound = false;	
	var isReady = false;
	var readyList = [];

	// Handle when the DOM is ready
	function domReady() {
		// Make sure that the DOM is not already loaded
		if(!isReady) {
			// Remember that the DOM is ready
			isReady = true;
        
	        if(readyList) {
	            for(var fn = 0; fn < readyList.length; fn++) {
	                readyList[fn].call(window, []);
	            }
            
	            readyList = [];
	        }
		}
	};

	// From Simon Willison. A safe way to fire onload w/o screwing up everyone else.
	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
	    window.onload = func;
	  } else {
	    window.onload = function() {
	      if (oldonload) {
	        oldonload();
	      }
	      func();
	    }
	  }
	};

	// does the heavy work of working through the browsers idiosyncracies (let's call them that) to hook onload.
	function bindReady() {
		if(readyBound) {
		    return;
	    }
	
		readyBound = true;

		// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
		if (document.addEventListener && !browser.opera) {
			// Use the handy event callback
			document.addEventListener("DOMContentLoaded", domReady, false);
		}

		// If IE is used and is not in a frame
		// Continually check to see if the document is ready
		if (browser.msie && window == top) (function(){
			if (isReady) return;
			try {
				// If IE is used, use the trick by Diego Perini
				// http://javascript.nwbox.com/IEContentLoaded/
				document.documentElement.doScroll("left");
			} catch(error) {
				setTimeout(arguments.callee, 0);
				return;
			}
			// and execute any waiting functions
		    domReady();
		})();

		if(browser.opera) {
			document.addEventListener( "DOMContentLoaded", function () {
				if (isReady) return;
				for (var i = 0; i < document.styleSheets.length; i++)
					if (document.styleSheets[i].disabled) {
						setTimeout( arguments.callee, 0 );
						return;
					}
				// and execute any waiting functions
	            domReady();
			}, false);
		}

		if(browser.safari) {
		    var numStyles;
			(function(){
				if (isReady) return;
				if (document.readyState != "loaded" && document.readyState != "complete") {
					setTimeout( arguments.callee, 0 );
					return;
				}
				if (numStyles === undefined) {
	                var links = document.getElementsByTagName("link");
	                for (var i=0; i < links.length; i++) {
	                	if(links[i].getAttribute('rel') == 'stylesheet') {
	                	    numStyles++;
	                	}
	                }
	                var styles = document.getElementsByTagName("style");
	                numStyles += styles.length;
				}
				if (document.styleSheets.length != numStyles) {
					setTimeout( arguments.callee, 0 );
					return;
				}
			
				// and execute any waiting functions
				domReady();
			})();
		}

		// A fallback to window.onload, that will always work
	    addLoadEvent(domReady);
	};

	// This is the public function that people can use to hook up ready.
	DomReady.ready = function(fn, args) {
		// Attach the listeners
		bindReady();
    
		// If the DOM is already ready
		if (isReady) {
			// Execute the function immediately
			fn.call(window, []);
	    } else {
			// Add the function to the wait list
	        readyList.push( function() { return fn.call(window, []); } );
	    }
	};
    
	bindReady();
	
})();