// Hover events for top menu for IE6 only
if ($.browser.msie && $.browser.version=="6.0") {
    $('#top-menu .level1 li[id^="item"]').hover(
        function() {
            $(this).css('border-left','1px solid #ad8d5e');
            $(this).css('border-right','1px solid #ad8d5e');
            $(this).children('ul').css('display','block');
        },
        function() {
            $(this).css('border-left','none');
            $(this).css('border-right','none');
            $(this).children('ul').css('display','none');
        }
    );
}

// Open certain links as a popup. These are defined by adding rel="popup" to the link
var w = '';
var getLink = '';
$('a[rel="popup"]').click(function(e) {
    e.preventDefault();
    getLink = $(this).attr('href');
    $(this).attr('target','');
    w = window.open(getLink,'','width=970,height=600,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no');
    if (w == null) {
        alert('The window could not opened because you have a pop-up blocker installed on your browser.\n\nPlease refer to your pop-up blocker documentation to see how you may deactivate it when you wish to allow a website to open a new window.');
        return;
    }
    w.focus();
    return w;
});

var setLang2 = '';
var itemLang = '';
// Set language selection drop down to current language if available
if (document.getElementById('language-change')) {
    setLang2 = languageController.getUserSiteLanguage();
    if (setLang2 == undefined) {
        $('#language-change h2').html('In your language');
    }
    else {
        itemLang = $('#select-language li a[href*="'+setLang2+'/"]').html();
        if (itemLang == null) {
            itemLang = $('#select-language li a[href*="/'+setLang2+'"]').html();            
        }
        $('#language-change h2').html(itemLang);
    }
}

// Hover on language selection drop down
$('#language-change').hover(
    function() {
        $('#select-language').css('display','block');
    },
    function() {
        $('#select-language').css('display','none');
    }
);

// Prep modal popup
if (document.getElementById('divSummary')) {
    $('#divSummary').jqm({modal: true});
}

// Small Aus Map in global course search panel
function ausMapSwitchSmall(whichState) {
    $('#small-aus-map').attr('src','/images/useruploadedimages/11/aus-map-'+whichState+'-small.gif');
    $('#small-aus-map').css('cursor','pointer');
}

function ausMapOffSmall() {
    $('#small-aus-map').attr('src','/images/useruploadedimages/11/map_australia.png');
    $('#small-aus-map').css('cursor','default');
}

function ausMapSelectionSmall(stateSel) {
    $('#ctl00_CourseSearchControl1_StateDropList').attr('value', stateSel);
}

$('#ctl00_CourseSearchControl1_StateDropList').change(function() {
    ausMapSwitchSmall($(this).attr('value'));
});

// Interactive Map functions
$('#aus-map-large').hide();
$('#institute-info').hide();
function worldMapSelection() {
    $('#aus-map-large img').attr('width','0px');
    $('#aus-map-large img').attr('height','0px');
    $('#world-map-large img').animate({
        width:"0px",
        height:"0px"
        },750, function() {
            $('#institute-info').show();
            $('#world-map-large').hide();
            $('#aus-map-large').show();
            $('#aus-map-large img').animate({
                width:"321px",
                height:"266px"
        },750);
    });
}

function worldMapOver() {
    $('#world-map-large img').css('cursor','pointer');
}

function worldMapOut() {
    $('#world-map-large img').css('cursor','default');
}

function ausMapSwitchLarge(whichState) {
    $('#aus-map-large img').attr('src','/images/useruploadedimages/11/aus-map-'+whichState+'-large.gif');
    $('#aus-map-large img').css('cursor','pointer');
}

function ausMapOffLarge() {
    $('#aus-map-large img').attr('src','/images/useruploadedimages/11/aus-map-off-large.gif');
    $('#aus-map-large img').css('cursor','default');
}

function ausMapSelectionLarge(stateSel, language) {
    $('#state-large img').attr('src','/images/useruploadedimages/11/state-'+stateSel+'-large.gif');	
    $('#aus-map-large img').animate({
        width:"0px",
        height:"0px"
        },750, function() {
            $('#aus-map-large').hide();
            $('#state-large').show();
            $('#state-large img').animate({
                width:"321px",
                height:"266px"
        },750, function() {
            $('#state-info').css('background-color','#E6E6E6');
            $('#state-info').css('border','1px solid #555');
            $('#state-info').css('overflow-y','scroll');
            $('#state-info').load('/'+language+'/StateInfo/'+stateSel+' .stateInfo');
            $('#institute-info').css('background-color','#E6E6E6');
            $('#institute-info').css('border','1px solid #555');
            $('#institute-info').css('overflow-y','scroll');
            $('#institute-info').load('/'+language+'/InstitutionList/'+stateSel);
        });
    });    
}

$('#state-large').hide();
$('#state-large img').attr('width','0px');
$('#state-large img').attr('height','0px');
$('#state-large img').click(function() {
    $('#state-large img').animate({
        width:"0px",
        height:"0px"
    },750, function() {
        $('#state-large').hide();
        $('#aus-map-large').show();
        $('#aus-map-large img').animate({
            width:"321px",
            height:"266px"
        },750);
    });	
});

// font resize
$(function(){
    var maxResize = 3;
    var currentResize = 0;
    $('.fontChange').click(function(){
        if (document.getElementById('page-content')) {
            var ourText = $('.container');
        }
        else if (document.getElementById('TROuterTable')) {
            var ourText = $('#MainTableForContent');
        }        
        var currFontSize = ourText.css('fontSize');
        var finalNum = parseFloat(currFontSize, 10);
        var stringEnding = currFontSize.slice(-2);
        if (this.id == 'large' && currentResize < maxResize) {
            finalNum *= 1.1;
            currentResize = currentResize+1;
        }
        else if (this.id == 'small' && currentResize > 0) {
            finalNum /=1.1;
            currentResize = currentResize-1;
        }
        ourText.css('fontSize', finalNum + stringEnding);
    });
});

// refer a friend popup
if (document.getElementById('refer-friend')) {
    $('#refer-friend').jqm({modal: true});
}
function ReferFriendOpen(strURL, intArticleID, strPage) {
    var referFriend = strPage + '?Article=' + intArticleID + '&' + strURL;
    $('#refer-friend iframe').attr('src',referFriend);
    $('#refer-friend').jqmShow();
}

//rotating news on home page
$('.home-campaign').append('<ul class="rotateButtons"></ul>');
var progressInterval = "";
var currentItem = 1;
var numItems = $('.home-campaign .mainItem').length + $('.home-campaign .subItem').length;
for (var i=0; i<numItems; i++) {
    $('.home-campaign .rotateButtons').append('<li>Item '+i+'</li>');
}
$('.home-campaign .rotateButtons li:first').css('background-position','bottom left');
if (numItems > 1) {
    progessInterval = setInterval("progress()", 5000);
}

function progress() {
    clearTimeout(progessInterval);
    if (currentItem == 1) {
        $('.home-campaign .mainItem').fadeOut('slow');
        $('.home-campaign .subItem:eq(0)').fadeIn('slow');
        currentItem++;
    }
    else if (currentItem > 1 && currentItem < numItems) {
        var currentFeature = $('.home-campaign .subItem:visible');
        var nextFeature = $('.home-campaign .subItem:visible').next();
        $(currentFeature).fadeOut('slow');
        $(nextFeature).fadeIn('slow');
        currentItem++;
    }
    else if (currentItem == numItems) {
        $('.home-campaign .subItem:visible').fadeOut('slow');
        $('.home-campaign .mainItem').fadeIn('slow');
        currentItem = 1;
    }
    $('.home-campaign .rotateButtons li').css('background-position','top left');
    $('.home-campaign .rotateButtons li:nth-child('+currentItem+')').css('background-position','bottom left');
    progessInterval = setInterval("progress()", 5000);
}

//news cycle button click
$('.rotateButtons li').click(function() {
    clearTimeout(progessInterval);
    currentItem = $(this).index()+1;
    progressNews();
});

function progressNews() {
    $('.home-campaign .mainItem').fadeOut('slow');
    $('.home-campaign .subItem:visible').fadeOut('slow');
    if (currentItem == 1) {
        $('.home-campaign .mainItem').fadeIn('slow');
    }
    else {
        $('.home-campaign .subItem:eq('+(currentItem-2)+')').fadeIn('slow');
    }
    $('.home-campaign .rotateButtons li').css('background-position','top left');
    $('.home-campaign .rotateButtons li:nth-child('+currentItem+')').css('background-position','bottom left');    
    progessInterval = setInterval("progress()", 5000);
}


