
var general = new function(){

    var jar = null;

    this.init = function() {        

        jar = new CookieJar({
            expires: 2592000,
            path: '/'
        });

        if(/affId=([^&]+)/.test(window.location.href)) {
            var data = {id :''+/affId=([^&]+)/.exec(window.location.href)[1]+''}
            storeCookie(data);
        }
        else if(readCookie()) {
            if(aid == '69714'){
                $('phone').show();      
            }
            else {
                $('phone').hide();                 
            }
            waitBox_hide();
            callLink_hide();
            affiliate_hide();
        }
        else {
            $('phone').show();
            callLink_show();
            affiliate_show();       
        } 
        
        /* Travel Pixel Specific code*/
        
        var aid = gup('affId');  
        var cookie_id = readCookieData(); 
        
        if(aid == '69714' || cookie_id == '69714' ){
            $('phone').replace('<img alt="Call at low rate on 08444 77 00 84" src="http://static.traveltek.net/images/www.lowcostcruising.com/v3/travelpix_tel.gif" id="phone" style="">');  
            $('phone').show();
            waitBox_hide(); 
        }
        
        if(aid != false || cookie_id != false){
            callLink_hide();
            affiliate_hide();         
        }                                                                                  
    }

    function storeCookie(data) {
        jar.put('cruising', data);
    }
    
    function readCookie() {
            return jar.get('cruising') != null;
        }
        
    function readCookieData(){
            if(jar.get('cruising') != null){
                cookie = jar.get('cruising')    
            }
            
            if(cookie.id != null){
                var id = cookie.id;     
            }
            if(id == null){
             id = false;    
            }     
            return id;      
    } 
    
    function affiliate_hide(){
        if($$('.affiliate_hide') != undefined){ 
            $$('.affiliate_hide').each(Element.hide);                     
        }          
    } 
    
    function affiliate_show(){
        if($$('.affiliate_hide') != undefined){ 
            $$('.affiliate_hide').each(Element.show);                     
        }         
    }   
     
    function callLink_hide(){
        if($$('.callLink') != undefined){    
            $$('.callLink').each(Element.hide);
        }        
    } 
    
    function callLink_show(){
        if($$('.callLink') != undefined){    
            $$('.callLink').each(Element.show);
        }        
    } 
    function waitBox_hide(){
        if($$('.waitBox') != undefined){    
            $$('.waitBox').each(Element.hide);
        }        
    }     

}

Event.observe(window, 'load', general.init);

function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return false;
    else
        return results[1];
}
