﻿/**
 *	Latitude Festival 2008 - Javascript Tools
 *
 *	@date		
 *	@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);
        }
    }
}



/**
 *  Lightbox functions
 */
var LBox = {

    detect: null,
    OS: null,
    browser: null,
    version: null,
    total: null,
    thestring: null,
    place: null,
    
    overlayBox: null,
    leightboxHolder: null,
    lbObject: null,

    init: function(args) {
        
        LBox.overlayBox = args[0];
        LBox.leightboxHolder = args[1];
        LBox.detect = navigator.userAgent.toLowerCase();
        LBox.getBrowserInfo();
        LBox.addLightboxMarkup();
	    
	    var lbox = document.getElementsByClassName('lbOn');
	    for(i = 0; i < lbox.length; i++) {
		    LBox.lbObject = new lightbox(lbox[i], args);
	    }
    },
    
    lbOpen: function() {
        LBox.lbObject.activate();
    },
    
    printWindow: function(url) {
        var wRef = window.open(
            url, 
            'Downloads', 
            'width=641,height=1000,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0'
        );
        wRef.print();
    },
    
    getBrowserInfo: function() {
	    if (LBox.checkIt('konqueror')) {
		    LBox.browser = "Konqueror";
		    LBox.OS = "Linux";
	    }
	    else if (LBox.checkIt('safari')) LBox.browser 	= "Safari"
	    else if (LBox.checkIt('omniweb')) LBox.browser 	= "OmniWeb"
	    else if (LBox.checkIt('opera')) LBox.browser 	= "Opera"
	    else if (LBox.checkIt('webtv')) LBox.browser 	= "WebTV";
	    else if (LBox.checkIt('icab')) LBox.browser 	= "iCab"
	    else if (LBox.checkIt('msie')) LBox.browser 	= "Internet Explorer"
	    else if (!LBox.checkIt('compatible')) {
		    LBox.browser = "Netscape Navigator"
		    LBox.version = LBox.detect.charAt(8);
	    }
	    else LBox.browser = "An unknown browser";

	    if (!LBox.version) LBox.version = LBox.detect.charAt(LBox.place + LBox.thestring.length);

	    if (!LBox.OS) {
		    if (LBox.checkIt('linux')) LBox.OS 		= "Linux";
		    else if (LBox.checkIt('x11')) LBox.OS 	= "Unix";
		    else if (LBox.checkIt('mac')) LBox.OS 	= "Mac"
		    else if (LBox.checkIt('win')) LBox.OS 	= "Windows"
		    else LBox.OS 							= "an unknown operating system";
	    }
    },
    
    checkIt: function(string) {
	    LBox.place = LBox.detect.indexOf(string) + 1;
	    LBox.thestring = string;
	    return LBox.place;
    },
    
    addLightboxMarkup:function() {
        
        // Overlay Box
	    var bod = document.getElementsByTagName('body')[0];
	    var overlayBox = document.createElement('div');
	    overlayBox.id = LBox.overlayBox;
	    bod.appendChild(overlayBox);
    	
    	// Lighbox Box
	    var leightboxHolder = document.createElement('div');
	    leightboxHolder.id = LBox.leightboxHolder;
	    bod.appendChild(leightboxHolder);
	    var lb_container = document.createElement('div');
	    lb_container.className = 'lb_container';
	    leightboxHolder.appendChild(lb_container);
    
    }
    
}



/**
 *  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
	        );
	        
	        
	        var qs = location.href.split('?')[1];
            if(qs != 'undefined' && qs != null) {
                if(qs.indexOf('info') > 0) { // Info page
                    var cid = qs.split('&')[0].split('=')[1];
                    myAccordion.showThisHideOpen(stretchers[cid-1]);
                } else {
                    // Unknown parameter - reload page with no querystring
                    var tmp = location.href.split('?')[0].split('/');
                    var section = tmp[tmp.length-2];
                    location.href = '/' + section + '/';
                }
            } else {
                // Default - open first div
                this.openFirstElement = args[5];
	            if(this.openFirstElement) {
	                myAccordion.showThisHideOpen(stretchers[0]);
	            }
            }
	        
	        // hide loader
	        //var loader = $('loader');
	        //if(loader != null) loader.style.display = 'none';	        
	        
	        // 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;
        }
    }
    
};



/**
 *  Tickets page Functions
 */
var Tickets = {
    
    ticketsId: null,               // Block ID containing ALL Tickets details for ALL Categories
    ticketsClass: null,            // Block Class containing Specific Tickets details
    ticketsHeadersId: null,        // Block ID containing ALL Tickets headers
    ticketsHeaderClass: null,      // Block Class containing Specific Tickets header
    activeColor: null,          // Color of active header
    
    ticketsItems: new Array(),
    ticketsHeaders: new Array(),
    
    init: function(args) {
        
        this.ticketsId = args[0];
        this.ticketsClass = args[1];
        this.ticketsHeadersId = args[2];
        this.ticketsHeaderClass = args[3];
        Tickets.activeColor = args[4];
        
        // Build Tickets blocks objects
        var block = $(this.ticketsId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.ticketsClass) {
                var tmp = el[i];
                Tickets.setParam(tmp, 'catId', el[i].id.split(':')[0]);
                Tickets.setParam(tmp, 'cId', el[i].id.split(':')[1]);
                Tickets.ticketsItems.push(tmp);
            }
        }
        
        // Disable headers links & add click events
        var block = $(this.ticketsHeadersId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.ticketsHeaderClass) {
                var aTags = el[i].getElementsByTagName('a');
                var aL = aTags.length;
                for(j=0;j<aL;j++) {
                    Tickets.setParam(aTags[j], 'catId', aTags[j].id.split(':')[0]);
                    Tickets.setParam(aTags[j], 'cId', aTags[j].id.split(':')[1]);
                    aTags[j].onclick = function() {
                        Tickets.showInfo(this);
                        return false;
                    }
                    Tickets.ticketsHeaders.push(aTags[j]);
                }
            }            
        }
        
        // Show first Tickets block
        Tickets.ticketsItems[0].style.display = 'block';
        Tickets.ticketsHeaders[0].style.color = Tickets.activeColor;
        
    },
    
    showInfo: function(el) {
        var activeEl = null;
        var l = Tickets.ticketsItems.length;
        for(i=0;i<l;i++) {
            if(Tickets.getParam(Tickets.ticketsItems[i], 'catId') == Tickets.getParam(el, 'catId')) {
                if(Tickets.getParam(Tickets.ticketsItems[i], 'cId') == Tickets.getParam(el, 'cId')) {
                    Tickets.ticketsItems[i].style.display = 'block';
                    activeEl = el;
                } else {
                    Tickets.ticketsItems[i].style.display = 'none';
                }
            } else {
                Tickets.ticketsItems[i].style.display = 'none';                
            }
        }
        if(activeEl != null) {
            Tickets.activate(el);
        }    
    },
    
    activate: function(el) {
        var l = Tickets.ticketsHeaders.length;
        for(i=0;i<l;i++) {
            if(Tickets.ticketsHeaders[i] == el) {
                Tickets.ticketsHeaders[i].style.color = Tickets.activeColor;
            } else {
                Tickets.ticketsHeaders[i].style.color = '';
            }
        }
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    },
    
    getParam: function(e, param) {
        return e[param];
    }
    
};



/**
 *  Info page active effect functions
 *  Called after the accordion effect is over
 */
var ActiveEffects_Info = {
    
    mode: '',
    obj: null,
    tracker: 0,
    
    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;
        }
        
        // Call the Info init function - only once
        if(this.tracker <= 0) {
            this.tracker++;
            var args = new Array('infoHolder', 'infoRightBlock', 'infoHeadersHolder', 'infoHeader', '#000');
            Info.init(args);
        }
    }
    
};


/**
 *  Info page Functions
 */
var Info = {
    
    infoId: null,               // Block ID containing ALL Info details for ALL Categories
    infoClass: null,            // Block Class containing Specific Info details
    infoHeadersId: null,        // Block ID containing ALL Info headers
    infoHeaderClass: null,      // Block Class containing Specific Info header
    activeColor: null,          // Color of active header
    
    infoItems: new Array(),
    infoHeaders: new Array(),
    
    init: function(args) {
        
        this.infoId = args[0];
        this.infoClass = args[1];
        this.infoHeadersId = args[2];
        this.infoHeaderClass = args[3];
        Info.activeColor = args[4];
        
        // Build info blocks objects
        var block = $(this.infoId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.infoClass) {
                var tmp = el[i];
                Info.setParam(tmp, 'catId', el[i].id.split(':')[0]);
                Info.setParam(tmp, 'faqId', el[i].id.split(':')[1]);
                Info.infoItems.push(tmp);
            }
        }
        
        // Disable headers links & add click events
        var block = $(this.infoHeadersId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.infoHeaderClass) {
                var aTags = el[i].getElementsByTagName('a');
                var aL = aTags.length;
                for(j=0;j<aL;j++) {
                    Info.setParam(aTags[j], 'catId', aTags[j].id.split(':')[0]);
                    Info.setParam(aTags[j], 'faqId', aTags[j].id.split(':')[1]);
                    aTags[j].onclick = function() {
                        Info.showInfo(this);
                        return false;
                    }
                    Info.infoHeaders.push(aTags[j]);
                }
            }            
        }
        
        // Show correct block function of query string
        var qs = location.href.split('?')[1];
        if(qs != 'undefined' && qs != null) {
            var o = new Object;
            Info.setParam(o, 'catId', qs.split('&')[0].split('=')[1]);
            Info.setParam(o, 'faqId', qs.split('&')[1].split('=')[1]);
            Info.showInfo(o);
        } else {
            // Default
            Info.showInfo(Info.infoItems[0]);
        }
        
    },
    
    showInfo: function(el) {
        var activeEl = null;
        var l = Info.infoItems.length;
        for(i=0;i<l;i++) {
            if(Info.infoItems[i].catId == el.catId) {
                if(Info.infoItems[i].faqId == el.faqId) {
                    Info.infoItems[i].style.display = 'block';
                    activeEl = el;
                } else {
                    Info.infoItems[i].style.display = 'none';
                }
            } else {
                Info.infoItems[i].style.display = 'none';                
            }
        }
        if(activeEl != null) {
            Info.activate(el);
        }
        Info.hideLoader();
    },
    
    activate: function(el) {
        var l = Info.infoHeaders.length;
        for(i=0;i<l;i++) {
            if(Info.infoHeaders[i].catId == el.catId) {
                if(Info.infoHeaders[i].faqId == el.faqId) {
                    Info.infoHeaders[i].style.color = Info.activeColor;
                } else {
                    Info.infoHeaders[i].style.color = '';
                }
            } else {
                Info.infoHeaders[i].style.color = '';         
            }
        }
    },
    
    hideLoader: function() {
        var loader = $('loader');
	    if(loader != null) loader.style.display = 'none';
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    },
    
    getParam: function(e, param) {
        return e[param];
    }
    
};



/**
 *  Arenas pages Functions
 */
var Arenas = {

    hId: null,
    aDesc: null,
    
    init: function(args) {
        
        this.hId = args[0];
        this.aDesc = args[1];
        
        var header = $(this.hId);
        var desc = $(this.aDesc);
        
        if(header != null) {
            header.innerHTML = desc.innerHTML;
        }
        
        /** Add SIFR **/
        if(typeof sIFR == "function"){
	        sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"/_Resources/flash/sifr-grant.swf", sColor:"#00743E", sLinkColor:"#00743E", sHoverColor:"#00743E", sWmode: "transparent", sFlashVars:"textalign=center"}));
        };
    }
    
};



/**
 *  Partners page Functions
 */
var Partners = {
    
    partnersId: null,               // Block ID containing ALL Partners details
    partnersDetailsClass: null,     // Block Class containing Partners details
    partnersHeaderClass: null,       // Block Class containing Partners headers
    
    partnersItems: new Array(),
    partnersHeaders: new Array(),
    
    init: function(args) {
        
        this.partnersId = args[0];
        this.partnersDetailsClass = args[1];
        this.partnersHeaderClass = args[2];
        
        // Build Partners Details objects
        var block = $(this.partnersId);
        var el = block.getElementsByTagName('div');
        var el_length = el.length;
        for(i=0;i<el_length;i++) {
            if(el[i].className == this.partnersDetailsClass) {
                var tmp = el[i];
                Partners.setParam(tmp, 'pId', el[i].id);
                Partners.partnersItems.push(tmp);
            }
        }
        
        // Disable headers links & add click events
        var aTags = block.getElementsByTagName('a');
        var aL = aTags.length;
        for(i=0;i<aL;i++) {
            if(aTags[i].className == this.partnersHeaderClass) {
                Partners.setParam(aTags[i], 'pId', aTags[i].id);
                aTags[i].onclick = function() {
                    Partners.showInfo(this);
                    return false;
                }
                Partners.partnersHeaders.push(aTags[i]);
            }            
        }
        
        // Show first Tickets block
        Partners.partnersItems[5].style.display = 'block';
        
    },
    
    showInfo: function(el) {
        var l = Partners.partnersItems.length;
        for(i=0;i<l;i++) {
            if(Partners.getParam(Partners.partnersItems[i], 'pId') == Partners.getParam(el, 'pId')) {
                Partners.partnersItems[i].style.display = 'block';
            } else {
                Partners.partnersItems[i].style.display = 'none';
            }
        }    
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    },
    
    getParam: function(e, param) {
        return e[param];
    }
    
};



/**
 *  Artist Search Functions
 */
var ArtistSearch = Class.create();
ArtistSearch.prototype = {

    s_form: null,
    s_input: null,
    s_button: null,
    s_redirect: '/search/search.aspx?aid=',
    
    initialize: function(id, s, b) {
        this.s_form = $(id);
        
        this.s_input = $(s);
        this.setParam(this.s_input, 'caller', this);
        this.s_input.onmouseup = function() {
            this.caller.clearField();
        }
        this.s_input.onkeypress = function(event) {
            if(this.caller.checkEnter(event)) {
                if(this.caller.s_input.value != '') {
                    this.caller.s_submit();
                } else {
                    alert("The search criteria cannot be blank!");
                    this.caller.s_input.focus();
                    return false;
                }
            }
        }
        
        this.s_button = $(b);
        this.setParam(this.s_button, 'caller', this);
        this.s_button.onclick = function() {
            if(this.caller.s_input.value != '') {
                this.caller.s_submit();
            } else {
                alert("The search criteria cannot be blank!");
                this.caller.s_input.focus();
                return null;
            }
        }
    },
    
    /** Checks whether keypress is "enter" **/
    checkEnter: function(e) {
        var characterCode;
        if(e && e.which) { //if which property of event object is supported (NN4)
            e = e;
            characterCode = e.which; //character code is contained in NN4's which property
        } else {
            e = event;
            characterCode = e.keyCode; //character code is contained in IE's keyCode property
        }
        if(characterCode == 13) {
            return true;
        } else {
            return false;
        }
    },
    
    s_submit: function() {
        this.s_form.action = this.s_redirect + this.s_input.value;
        this.s_form.submit();
    },

    clearField: function() {
        this.s_input.value = '';
    },
    
    setParam: function(e, param, value) {
        e[param] = value;
    }
    
};        