// Show/Hide


var Site = {
    init: function() {
        Site.Resources.init()
        Site.Profiles.init()
    },
    
    Resources: {
        init: function() {
            this.wrapper = $('helpfulsitestext')
            if (!this.wrapper) return                        
            
            this.openSRC    = window.root+'images/hcp/expand_btn.gif'
            this.closeSRC   = window.root+"images/hcp/hide_btn.gif" 
                                   
            this.status      = $$('.vertical_status')
            this.statImgs    = $$('.vertical_status img')
            this.toggles     = this.wrapper.getElements('h2 a')
            this.toggled     = this.wrapper.getElements('.toggled')
            
            this.toggled.each(function(el, i) {
                var mytog = el
                this.toggled[i] = new Fx.Slide(mytog).hide()
            }, this)
            
            this.statImgs.each(function(el, i) {
                el.setProperties({'src': this.openSRC, 'alt':'show/hide'})
            }, this)
                        
            this.toggles.each(function(tog, i) {
                tog.addEvent('click', function(e) {
                    e.stop()
                    var state = tog.hasClass('open')
                    if (state) {
                        this.statImgs[i].set('src', this.openSRC)
                        tog.removeClass('open')                                          
                    }
                    else {
                        this.statImgs[i].set('src', this.closeSRC)
                        tog.addClass('open')                                                      
                    }
                    this.toggled[i].toggle()                    
                }.bind(this))
            }, this)                        
	
        }
    },
    
    Profiles: {
    	curr: null,
        init: function() {
        	this.wrapper = $('patientProfiles')
        	if (!this.wrapper) return
        	
        	this.pages	= $$('.tabContent')
        	this.pages.each(function(page, i) {
        		page.setStyle('display', 'none')        		
        	})
        	
    		//tracking values
    		//tabs are numbered 0 through 3
        	this.trackData = {
        		0: {dcsuri: "lovenox-patient-profiles.aspx"},				//medical
        		1: {dcsuri: "lovenox-patient-profiles-surgical.aspx"},		//surgical
        		2: {dcsuri: "lovenox-patient-profiles-treatment.aspx"}, 	//treatment
        		3: {dcsuri: "lovenox-patient-profiles-acs.aspx"}			//acute
        	}            	
        	
        	this.tabs 	= $$('.ppTabs a')
        	this.tabs.each(function(tab, i) {
    			tab.set('href', 'javascript:void(0);')
    			tab.addEvent('click', function(e) {
    				e.stop()
    				this.showPage(i)
    			}.bind(this))
    			
    		}, this)        	        	
        	this.showingFirst = true       		    		
        	this.showFirst()        	        	
        },
        
        showFirst: function() {        	
        	var tab = (window.location.href.contains('?')) ? $A(window.location.href.split('?')).getLast() : false
        	var ex = /^.{0,}tab=(\w+)&{0,}/
        	
        	var start = ($type(tab) == 'string' && tab.contains('tab=')) ? $A(tab.match(ex)).getLast()  : false
        	
        	var map = {
        		'medical': 0,
        		'surgical': 1,
        		'abdominal': 1,
        		'treatment': 2,
        		'acute': 3
        	}       	
        	this.showPage(map[start] || 0)
        	
        	if (start == 'abdominal') {
				(function(){ window.location.hash = 'abdominal' }).delay(1000);        		
        	}       	
        },
        
        showPage: function(i) {
        	if ($chk(this.curr) && this.curr == i) return
        	
        	if ($chk(this.curr)) {
        		this.tabs[this.curr].removeClass('active')
        		this.pages[this.curr].setStyle('display', 'none')
        	}
        	
    		this.tabs[i].addClass('active')
    		this.pages[i].setStyle('display', '')        	
        	
    		//don't track initial tab if its the default tab
    		//default page tracking will make that call
    		if (this.showingFirst) {
    			if (i != 0) this.trackTab(i)
    		}
    		else this.trackTab(i)
    		
        	
        	this.curr = i
        	this.showingFirst = false
        },
        
		trackTab: function(index) {
			var template 	= "['DCS.dcssip', '{dcspath}', 'DCS.dcsuri', '{dcsuri}']"
			var context 	= this.trackData[index] || {}
			var defaults	= new Hash({dcsuri: ''})
			
			defaults.extend(context)

			var arr = JSON.decode(template.substitute(defaults))
			
			dcsMultiTrack.apply(this, arr)		
			
			return this
		}        
    }
}
	

window.addEvent('domready', function() {
    Site.init()
})
