﻿function displayVirtualTour(file) {
	var frm = frames['frmVirtual'];	
	frm.document.open();
	frm.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
	frm.document.writeln('<html>');
	frm.document.writeln('<head>');
	frm.document.writeln('	<title>Untitled</title>');
	frm.document.writeln('	<style type="text/css">');
	frm.document.writeln('	body {margin:0px;padding:0px;}');
	frm.document.writeln('	</style>');
	frm.document.writeln('</head><body>');
	frm.document.writeln('<applet  code="IpixViewer.class"  width="297" height="223" archive="IpixViewer.jar" codebase="/applets/" name="IpixViewer">');
    frm.document.writeln('<param name="URL" value="' +  file + '">');
    frm.document.writeln('<param name="Toolbar" value="small">');
    frm.document.writeln('<param name="SpinSpeed" value="-2">');
    frm.document.writeln('<param name="SpinStyle" value="flat">');
    frm.document.writeln('<PARAM NAME="helpurl" VALUE="http://www.ipix.com/support/posting/examples/help_4ff.html">');
	frm.document.writeln('<param name="helpframe" value="_blank">');
	frm.document.writeln('</applet>');
	frm.document.write('</body></html>');
	frm.document.close();
	return false;
}

var VirtualTour = {
    elementSet : null,
	effect : null,
	init : function(elementSet,element,items) {
		window.addEvent('load', function(){
			VirtualTour._init(elementSet,element,items);			
		});
	},
	_init : function (elementSet,element,items) {
	    this.elementSet = $$(elementSet);
		if (!this.elementSet) return false;
		var addIndex = 0;
		this.elementSet.forEach(function(item) {		    
		    var divName = item.getChildren(element);		    
		    var divElement  = new Element('div', {'class': 'categorySection'});
		    divElement.inject(divName[0], 'after');		    
		    var itemSet = item.getChildren(items);
		    var explanationSet = item.getChildren('div.explanationSet');		    
		    itemSet.forEach(function(item2,index2) {
                var aThumbSet = item2.getChildren('a');	
                var divExplanationSet = explanationSet[index2].getChildren('div.explanation');		        
		        aThumbSet.forEach(function(aThumb,index3) {
		            aThumb.explainMain = explanationSet[index2];
		            aThumb.explainMainIndex = index2 + addIndex;
		            aThumb.explain = divExplanationSet[index3];
		            aThumb.explainHeight = divExplanationSet[index3].offsetHeight;
		            aThumb.addEvent('click',VirtualTour.thumbMenuClick.bindWithEvent(aThumb));
		            aThumb.explainMain.setStyle('height', '0px');
		            aThumb.explain.setStyle('height', '0px');
		        });
		        item2.injectInside(divElement);			
		    });		    
		    addIndex = addIndex + itemSet.length;		    
		    var categorySet = divName[0].getElements('a');
		    var ipixIMGSet = divElement.getChildren('div.ipixIMG');
		    if (categorySet.length > 0)
		    {
                var categoryAccordion = new Accordion($('accordion'), categorySet, ipixIMGSet, {
                show: categorySet.length - 1,
                opacity: false,                
                onActive: function(toggler, element){      
                    var ipixIMGSet = divElement.getChildren('div.ipixIMG');
                    ipixIMGSet.forEach(function(ipixIMG) {
                        var aThumbSet = ipixIMG.getChildren('a');
                        aThumbSet.forEach(function(Thumb) {
		                    Thumb.removeClass("active");
		                });
                    });
		            var divExplainSet = item.getChildren('div.explanationSet');        		    
		            divExplainSet.forEach(function(item2) {
		                this.effect = new Fx.Tween(item2);
                        this.effect.start('height', '0px');                        
		                var divExplanationSet = item2.getChildren('div.explanation');
		                divExplanationSet.forEach(function(item3) {		                    
		                    this.effect = new Fx.Tween(item3);
                            this.effect.start('height', '0px');		                    
		                });
		            });
                }});
            }
        });
        $('ipixLeft').removeClass("hide");
	},
	thumbMenuClick : function(event) {	    
	    var divExplainSet = $$('div.explanation');
	    var currentHeight = 0;
	    divExplainSet.forEach(function(item,index) {
	        item.fade(0);
	        if (item.offsetHeight > currentHeight) 
	            currentHeight = item.offsetHeight;
	    });        
        var aThumbSet = $$('div.ipixIMG a');
        aThumbSet.forEach(function(Thumb,index) {
            Thumb.removeClass("active");
        });        
	    this.addClass("active");
	    var currentIndex = this.explainMainIndex;
	    var ExplainSet = $$('div.explanationSet');
	    ExplainSet.forEach(function(item,index) {
	        if (currentIndex != index)
	        {
	            VirtualTour.effect = new Fx.Tween(item);
	            VirtualTour.effect.start('height', '0');
	        }
	    });
	    VirtualTour.effect = new Fx.Tween(this.explainMain);
        VirtualTour.effect.start('height', this.explainHeight);
        VirtualTour.effect = new Fx.Tween(this.explain);
        VirtualTour.effect.start('height', this.explainHeight);
        this.explain.fade(1);
	}
}
VirtualTour.init('#ipixLeft .ipixWrap','.ipixName','div.ipixIMG');