/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function load_scripts() {
var scripts = new Array('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
var appscripts = new Array();
var holders = new Array();
for (i in scripts)
    {
        console.log('Sctipt '+i+' Loading');
        holders[i] = document.createElement('script');
        scripts[i].loaded = false;
        holders[i].type = 'text/javascript';
        holders[i].async = true;
        holders[i].src = scripts[i];
        console.log('going into onload script '+i);
        holders[i].onload = function() {
       scripts[i].loaded = true;
       console.log('Script '+i+' Loaded');
        }
        appscripts[i] = document.getElementsByTagName('script')[0]; appscripts[i].parentNode.insertBefore(holders[i], appscripts[i]);
    }
}




function check_scripts() {
 if (typeof(jQuery) == 'undefined')
{
    console.log('no JQuery');
    setTimeout('check_scripts()',200);
}
else {
    console.log('got Jquery');
  var $j = jQuery.noConflict();
  $j(document).ready(function() {
      bottombar.init();
  })
}
}
load_scripts();
check_scripts();
var bottombar = {
    init: function() {
    bottombar.bar = jQuery('.bottombar');
    bottombar.messages = new Array();
    bottombar.messages[0] = "<a href='http://www.azureoverseas.com/special-offers/refer-a-friend-to-win-an-ipad/'>Refer a Friend to Win an Ipad - Click Here to Learn More</a>";
        //bottombar.message2 = "Escape the Off Plan Risk -- All Our Properties are Now Key Ready";
        bottombar.bar.hide().delay(200).css('background','#D36208');
        if (bottombar.messages.length == 1)
            {
                bottombar.messageholder = jQuery("<p></p>").addClass('messageholder');
                bottombar.messageholder.appendTo(bottombar.bar)
                bottombar.messageholder.hide().addClass('message1').html(bottombar.messages[0]).show();
            }
            setTimeout('bottombar.animate()',2000);
            bottombar.bar.hover(function() {
            //console.log('hover in clear int');
            if (bottombar.rotator) { clearInterval(bottombar.rotator); delete bottombar.rotator}
        }, function() {
             //console.log('hover out reset int');
           if (!bottombar.rotator) { bottombar.rotator = setInterval('bottombar.showmessages()',6000); }
        })
    },
    animate: function() {
        bottombar.bar.show('500',function() {
            if (bottombar.messages.length > 1)
                {
                    bottombar.rotator = setInterval('bottombar.showmessages()',6000)
                }
        });
    },//TODO REWRITE SHOW MESSAGES FUNCTION to Use Array
    showmessages: function() {
        if ($j(bottombar.bar).find('.message1').length > 0)
            {
                //console.log(bottombar.message2)
                bottombar.messageholder.hide().removeClass('message1').addClass('message2').html(bottombar.message2).show();
            }
            else {
                // console.log(bottombar.message1);
                 bottombar.messageholder.hide().removeClass('message2').addClass('message1').html(bottombar.message1).show();
            }
        
    }
}
