﻿/**
 *	46664 - Nelson Mandela - Javascript Tools
 *
 *	@date		2008-03-04
 *	@author		Michael Giuliano
 *	@copyright	Live Nation (Music) UK
 */
 

   
/**
 *  Loader function
 *  Add a function to window.onload event
 */
function addLoadEvent(func, args) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = function() {
            func(args);
        }
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func(args);
        }
    }
}


/**
 *  Accordion Effects
 *  Initialises accordion, and desactivate links
 */
var StartEffects = {

    divId: null,
    displayClass: null,
    stretcherClass: null,
    specialEffects: null,
    disableIE6: false,
    openFirstElement: false,
    
    init: function(args) {
    
        this.disableIE6 = args[4];
        if(this.disableIE6) {
            var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
            var isIE6 = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7);
        } else {
            var isIE6 = false;
        }
        if (!isIE6) {
        
            this.divId = args[0];           // Block ID
            this.displayClass = args[1];    // Display block class name
            this.stretcherClass = args[2];  // Stretcher block class name
            this.specialEffects = args[3];  // Special effect to apply after the Accordion affect
            
            var stretchers = document.getElementsByClassName(this.stretcherClass);
            var toggles = document.getElementsByClassName(this.displayClass);
            
            // disable link
            var tl = toggles.length;
            for(i=0; i<tl; i++) {
                var aTags = toggles[i].getElementsByTagName("a");
                aTags[0].onclick = function() {
                    return false;
                };
            }
        
	        // accordion effect
	        var myAccordion = new fx.Accordion(
		        toggles, stretchers, {opacity: true, duration: 400}, this.specialEffects
	        );
	        
	        // Open correct div function of query string
            var offset = 0;
            var qs = location.href.split('?')[1];
            if(qs != 'undefined' && qs != null) {
                // Show disabled info
                if(qs == 'disabled') {
                    myAccordion.showThisHideOpen(stretchers[3]);
                }
            } else {
                // Default: open first div
                this.openFirstElement = args[5];
	            if(this.openFirstElement) {
	                myAccordion.showThisHideOpen(stretchers[0]);
	            }
            }
	        
	    }
	}
	
};


/**
 *  Activates the link with the "active" class
 */
var ActiveEffects = {
    
    mode: '',
    obj: null,
    
    init: function(m, o) {
        this.mode = m;
        this.obj = o;
        var aTag = this.obj.getElementsByTagName('a')[0];
        switch(this.mode) {
            case 'open':
                aTag.className = 'active';
                break;
            case 'close':
                aTag.className = '';
                break;
            case 'closeAndOpen':
                aTag.className = '';
                break;
        }
    }
    
};



/**
 *  Ticket page Functions
 */
var Tickets = {
    
    blockId: null,
    blockClass: null,
    headersId: null,
    
    ticketBlocks: new Array(),
    ticketDays: new Array(),
    
    init: function(args) {
        
        this.blockId = args[0];
        this.blockClass = args[1];
        this.headersId = $(args[2]);
                
        // Build info blocks objects
        var block = $(this.blockId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.blockClass) {
                var tmp = el[i];
                Tickets.setParam(tmp, 'name', el[i].title);
                Tickets.ticketBlocks.push(tmp);
            }
        }
        
        // Disable headers links & add click events
        var aTags = this.headersId.getElementsByTagName('a');
        var aL = aTags.length;
        for(i=0;i<aL;i++) {
            aTags[i].onclick = function() {
                Tickets.showInfo(this);
                return false;
            }
            Tickets.ticketDays.push(aTags[i]);
        }
        
        // Show first info block & activate 05 July
        Tickets.showBlock(Tickets.ticketBlocks[2]);
        Tickets.activate(Tickets.ticketDays[2]);
        
    },
    
    showInfo: function(el) {
        var l = Tickets.ticketBlocks.length;
        var activeEl = null;
        for(i=0;i<l;i++) {
            if(Tickets.getParam(Tickets.ticketBlocks[i], 'name') == el.title) {
                Tickets.showBlock(Tickets.ticketBlocks[i]);
                activeEl = el;
            } else {
                Tickets.hideBlock(Tickets.ticketBlocks[i]);
            }
        }
        Tickets.activate(activeEl);
    },
    
    showBlock: function(el) {
        el.style.display = 'block';
    },
    
    hideBlock: function(el) {
        el.style.display = '';
    },
    
    activate: function(el) {
        var l = Tickets.ticketDays.length;
        for(i=0;i<l;i++) {
            if(Tickets.ticketDays[i].title == el.title) {
                Tickets.ticketDays[i].className = 'active';
            } else {
                Tickets.ticketDays[i].className = '';
            }
        }
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    },
    
    getParam: function(e, param) {
        return e[param];
    }
    
};



/**
 *  FAQ page Functions
 */
var Info = {
    
    blockId: null,      // ID containing all the info blocks
    blockClass: null,   // Class of a info block
    headersId: null,    // ID containing the info headers
    
    infoBlocks: new Array(),
    infoHeaders: new Array(),
    
    init: function(args) {
        
        this.blockId = args[0];
        this.blockClass = args[1];
        this.headersId = $(args[2]);
                
        // Build info blocks objects
        var block = $(this.blockId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.blockClass) {
                var tmp = el[i].id.split('::');
                Info.setParam(el[i], 'catId', tmp[0]);
                Info.setParam(el[i], 'contentId', tmp[1]);
                Info.infoBlocks.push(el[i]);
            }
        }
        
        // Disable headers links & add click events
        var aTags = this.headersId.getElementsByTagName('a');
        var aL = aTags.length;
        for(i=0;i<aL;i++) {
            if(aTags[i].className == 'category_clickable') {
                var tmp = aTags[i].id.split('::');
                Info.setParam(aTags[i], 'catId', tmp[0]);
                Info.setParam(aTags[i], 'contentId', tmp[1]);
                aTags[i].onclick = function() {
                    Info.showInfo(this);
                    return false;
                }
                Info.infoHeaders.push(aTags[i]);
            }
        }
        
        // Show correct block function of query string
        var offset = 0;
        var qs = location.href.split('?')[1];
        if(qs != 'undefined' && qs != null) {
            // Show disabled info
            if(qs == 'disabled') {
                var l = Info.infoBlocks.length;
                for(i=0;i<l;i++) {
                    if(Info.getParam(Info.infoBlocks[i], 'catId') == 4) {
                        if(Info.getParam(Info.infoBlocks[i], 'contentId') == 1) {
                            Info.showBlock(Info.infoBlocks[i]);
                        } else {
                            Info.hideBlock(Info.infoBlocks[i]);
                        }                
                    } else {
                        Info.hideBlock(Info.infoBlocks[i]);
                    }
                }
            }
        } else {
            // Default: Show & activate first info block
            Info.showBlock(Info.infoBlocks[0]);
            Info.activate(Info.infoHeaders[0]);
        }
        
    },
    
    showInfo: function(el) {
        var l = Info.infoBlocks.length;
        var activeEl = null;
        for(i=0;i<l;i++) {
            if(Info.getParam(Info.infoBlocks[i], 'catId') == Info.getParam(el, 'catId')) {
                if(Info.getParam(Info.infoBlocks[i], 'contentId') == Info.getParam(el, 'contentId')) {
                    Info.showBlock(Info.infoBlocks[i]);
                    activeEl = el;
                } else {
                    Info.hideBlock(Info.infoBlocks[i]);
                }                
            } else {
                Info.hideBlock(Info.infoBlocks[i]);
            }
        }
        Info.activate(activeEl);
    },
    
    showBlock: function(el) {
        el.style.display = 'block';
    },
    
    hideBlock: function(el) {
        el.style.display = 'none';
    },
    
    activate: function(el) {
        var l = Info.infoHeaders.length;
        for(i=0;i<l;i++) {
            if(Info.getParam(Info.infoHeaders[i], 'catId') == Info.getParam(el, 'catId')) {
                if(Info.getParam(Info.infoHeaders[i], 'contentId') == Info.getParam(el, 'contentId')) {
                    Info.infoHeaders[i].style.color = '#975c07';
                } else {
                    Info.infoHeaders[i].style.color = '';
                }                
            } else {
                Info.infoHeaders[i].style.color = '';
            }
        }
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    },
    
    getParam: function(e, param) {
        return e[param];
    }
    
};