﻿ rangeForm = "closed";
var storyHeight
var techHeight
var mediaHeight
var gamesHeight
var btnArray
var data
var maxCompare = 4;
var totalCompare = 0;
var cboArray

var closedHeight = 50
//var currentFormName = "fmFilter";
var activeForm = ""
function pageInit(){


    // 'Filter the range' and 'Range finder' links
    // ------------------------------
    // Opens and closes the 'filter range/filter' forms
    if ($('fmStoryLink')){
      
        storyHeight = 250 //$('fmStoryLI').offsetHeight;
        techHeight = 110 //$('fmTechLI').offsetHeight;
        mediaHeight = 80 //$('fmMediaLI').offsetHeight;
        gamesHeight = 110 //$('fmGamesLI').offsetHeight;
        
        if($('fmStoryLink')){
            $('fmStoryLink').onclick = function(){
                filterAnim('story');
                return(false);
            }
        }
        if($('fmTechLink')){
            $('fmTechLink').onclick = function(){
                filterAnim('tech');
                return(false);
            }
        }
        if ($('fmMediaLink')){
	        $('fmMediaLink').onclick = function(){
                filterAnim('media');
                return(false);
            }
        }
        if($('fmGamesLink')){
            $('fmGamesLink').onclick = function(){
                filterAnim('games');
                return(false);
            }  
        } 		
    }
    if (activeForm == "" && $('fmStoryLink')){
     
        //filterAnim("story")
    }
    
    //performSearch();
    //setCompareLinks();
}

function filterAnim(activeForm){

    // If the range form is closed - open it and close the filter form
   
        if($('fmTechLink')){$('fmTechLink').className = "closedPanel"}
        if($('fmStoryLink')){$('fmStoryLink').className = "closedPanel"}
        if($('fmMediaLink')){ $('fmMediaLink').className = "closedPanel"}
        if($('fmGamesLink')){$('fmGamesLink').className = "closedPanel"}
	 
        if($('fmStoryLink')){if (activeForm != "story"){ new Effect.Morph('fmStoryLI', {style: 'height:'+closedHeight+'px;', duration: 0.3});}}
        if($('fmTechLink')){if (activeForm != "tech"){new Effect.Morph('fmTechLI', {style: 'height:'+closedHeight+'px;', duration: 0.3 });}}
        if($('fmMediaLink')){if (activeForm != "media"){ new Effect.Morph('fmMediaLI', {style: 'height:'+closedHeight+'px;',  duration: 0.3 });}}
        if($('fmGamesLink')){if (activeForm != "games"){new Effect.Morph('fmGamesLI', {style: 'height:'+closedHeight+'px;', duration: 0.3});	}}
		
		if (activeForm == "story"){
		   new Effect.Morph('fmStoryLI', {
			  style: 'height:'+storyHeight+'px;', // CSS Properties
			  duration: 0.3
			});	
		   $('fmStoryLink').className = "openedPanel"
		}else if (activeForm == "tech"){
		   new Effect.Morph('fmTechLI', {
			  style: 'height:'+techHeight+'px;', // CSS Properties
			  duration: 0.3
			});		
		   	$('fmTechLink').className = "openedPanel";
			
		}else if (activeForm == "media"){
		   new Effect.Morph('fmMediaLI', {
			  style: 'height:'+mediaHeight+'px;', // CSS Properties
			  duration: 0.3
			});		
		   $('fmMediaLink').className = "openedPanel"
		}else if (activeForm == "games"){
		   new Effect.Morph('fmGamesLI', {
			  style: 'height:'+gamesHeight+'px;', // CSS Properties
			  duration: 0.3
			});			
		   $('fmGamesLink').className = "openedPanel"
		}
}

function setCompareLinks(){
    // Add to Compare Checkboxes
    cboArray = $('searchResults').getElementsByTagName("input");
        for (var i=0; i < cboArray.length; i++) {
            if (cboArray[i].type == "checkbox"){       
                cboArray[i].onclick = function(){
                
                    addCompare(this.id,this.checked);
                }
            }
        }
    // Hide the compare button
    addCompare('','');
}

document.observe("dom:loaded",function() {pageInit();});
