//Simple Javascript functions //

// Icons
var question_icon  = 'url(http://www.cuc.claremont.edu/site/images/icons/help.png)';
var folder_icon = 'url(http://www.cuc.claremont.edu/site/images/folder.gif)';
var arrow_fwd = 'url(http://www.cuc.claremont.edu/site/images/arrow-fwd.gif)';
var arrow_fwd_active = 'url(/site/images/arrow-fwd-inner.gif)';
var arrow_down = 'url(http://www.cuc.claremont.edu/site/images/arrow-dwn_hover.gif)'; 
var current_icon;

//--------------------------------------------------------
// Add 'external' CSS class to all external links
//--------------------------------------------------------
var inherit = 'inherit'; // to bypass I.E.7 inability to interpret 'inherit' properly.
var is_expanded = false;

$().ready(function () {

    if ($.browser.msie && parseInt(jQuery.browser.version) == 7) {
        inherit = '';
    }

    $('.answer').hide(), $('answer bubble-top').hide(), $('.hide').hide();
    $('a[href^=mailto]').addClass('email');
    $('a[href$=pdf]').addClass('pdf');

    $('a:[href^=http]').click(function () { $(this).target = "_blank"; });
    $('a[href^=http]:not([href*=claremont])').addClass('external');

    $('#colleges a').removeClass('external'); // don't do the footer
    //$('a.internal:[href^=http]').click(function () { $(this).target = ""; }); // don't do specific links

    $('a.external').attr('title', $(this).attr('title') + ' [This link will open in a new window or tab]');
    $('a.external').attr({ target: "_blank" });

    $('a[href^=https://odyssey.cuc.claremont.edu]').attr('title', 'You must use Internet Explorer 7 to access Odyssey');

    // Sets icons for uls with nested uls 
    setSubUl();

    $('.collapsible').prepend('<div class="expandall"><a href="javascript:expand_all()">Expand all</a></div>');

   // $('.FAQ > ul > li').css('list-style-image', question_icon);
   // $('.FAQ ul li ol li').css('list-style-image', 'none')
    //$('.bubble-top ul').css('list-style-image', 'none');

    $('div.FAQ').prepend('<div class="expandall"><a href="">Expand all</a></div>');
    $('div.FAQ div.expandall').click(function (e) { e.preventDefault(); toggle_expand_all($(this)); e.restoreDefault(); });

    $('.expandableList > li').click(function () {
        $(this).next().toggle();
        return false;
    }).next().hide();

    //$(".description").tooltip({ effect: 'fade', position: 'bottom left' });
});
//--------------------------------------------------------------
function toggle_expand_all(div_id) 
{
    var text = div_id.text();
    var parent = div_id.parent();
    var prompt  = div_id.children().first();
    
    if(text=='Expand all') {
        prompt.text('Collapse all');
        div_id.css('background-image', 'url(http://www.cuc.claremont.edu/site/images/icons/collapseall.jpg)');
        $(' div').removeClass('bubble-head');
        $(' div').removeClass('bubble-bottom');
        $('.bubble-top').css('background', inherit);
        $('.ul alinklist').show();
        $('.bubble-top').show();
  } else {
        prompt.text('Expand all');
        $('.answer').hide();
        div_id.css('background-image', 'url(http://www.cuc.claremont.edu/site/images/icons/expandall.jpg)');
    }       
    
}
//--------------------------------------------------------
 function toggle_bubble(div_id)
{
    var $this = $("#" + div_id);
    if ($(this) == null) return;

    if($this.is(':visible')) {
        $this.fadeOut("fast");
        $this.css('background',inherit);
        $this.parent().children().remove('.bubble-head');
        $this.parent().children().remove('.bubble-bottom');
    } else {
        $this.css('background','url(http://www.cuc.claremont.edu/site/images/boxes/response-bubble-body.png)');
        $this.before('<div class="bubble-head"></div>');
        $this.parent().append('<div class="bubble-bottom"></div>');
        $this.fadeIn("fast");
    }
}
//---------------------------------------------------------------
function setSubUl()
{
    
           //$('ul.linklist').css( 'text-indent', '8px' );
           //$('li > ul > li').css('text-indent', '12px');
           
           $('li').has('ul.answer > li').css('list-style-image', folder_icon);
           $('ul.linklist li ul.answer').hide();

           $('ul.linklist').hover (
                function(){ current_icon = $(this).css('list-style-image'); $(this).css('list-style-image', arrow_fwd_active);},  
                function(){ $(this).css('list-style-image', current_icon); }
            );

           $('ul.linklist li').has('ul.answer > li').hover (
                function(){$(this).css('list-style-image', arrow_down); }, 
                function(){$(this).css('list-style-image', folder_icon)}
            );

           $('ul.expandList li').has('ul.expand > li').hover (
                function(){$(this).css('list-style-image', arrow_down); }, 
                function(){$(this).css('list-style-image', folder_icon)}
            );

            
}
//--------------------------------------------------------
function toggle(div_id) {
    var $this = $("#" + div_id);
    if ($(this) == null) return;
    if ($this.is(':visible')) $this.fadeOut("fast");
    else $this.slideDown("fast");
}
//--------------------------------------------------------
 function toggle_more(div_id)
{
	var e = document.getElementById(div_id);
    if(e==null) return;
    
	if (e.style.display == 'inline') {  
	        e.style.display = 'none';
	        e.previousSibling.innerHTML = 'More...';
	        //var less = e.nextSibling;
	        var less = e.parentNode.lastChild;
	        if (less != null) {
	            e.parentNode.removeChild(less);
	        } 
	} else {
        e.style.display='inline';
	    e.previousSibling.innerHTML='';
	    var less = document.createElement('a');
	    var mlink = "javascript:toggle_more('" + div_id + "')";
	    less.setAttribute("href", mlink);
	    less.setAttribute("class", "more");
        //less.setAttribute("id", div_id + "2");
	    less.innerHTML = "Less...";
    
	    e.parentNode.appendChild(less);
     }
}
// ----------------------Functions for the sliding tips ----------------- //
function toggleDiv(objname) {
    toggle(objname);
}

function expand_all() {
    if (is_expanded) {
        $('.answer').hide();
        $('.expandall a').text('Expand all');
        $('.expandall').removeClass('collapseall');
        is_expanded = false;
    } else {
        $('.answer').show();
        $('.expandall a').text('Collapse all');
        $('.expandall').addClass('collapseall');
        is_expanded = true;
    }
}
//----------------  CLSA calendar --------------------//
var current_month;
var bgcolor;

function switch_content(month_id, mnb)
{
 current_month = mnb;
    var tgt_div = document.getElementById('calendar-content');
    var month_div = document.getElementById(month_id);
    tgt_div.innerHTML = '<table class="calendar" >' + month_div.innerHTML + '</table>';
}
//-----------------------------------------------------
 function highlight_label( on )
{
    var elem = document.getElementById(current_month);
    if(on) { bgcolor=elem.style.background; }
    elem.style.background = on ? "#c6cca3" : bgcolor;
}
//-----------------------------------------------------
function viewCUCMap() 
{
//var url = "http://maps.google.com/maps?q=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hl=en&amp;cd=1&amp;ei=8483TIzUBYT2oATXufWPDQ&amp;sig2=lSwsnTqW0zOjJab9gRg87Q&amp;sll=34.101651,-117.713914&amp;sspn=0.006388,0.013937&amp;ie=UTF8&amp;view=map&amp;cid=6855595288345664401&amp;ved=0CEYQpQY&amp;hq=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hnear=&amp;ll=34.101624,-117.713914&amp;spn=0.00533,0.006437&amp;z=16&amp;iwloc=A&amp;source=embed";
//alert(url);
var win = window.open("", "CUCMap", "location=0,status=0,scrollbars=0,width=400,height=400");
win.document.write('<iframe width="400" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?q=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hl=en&amp;cd=1&amp;ei=8483TIzUBYT2oATXufWPDQ&amp;sig2=lSwsnTqW0zOjJab9gRg87Q&amp;sll=34.101651,-117.713914&amp;sspn=0.006388,0.013937&amp;ie=UTF8&amp;view=map&amp;cid=6855595288345664401&amp;ved=0CEYQpQY&amp;hq=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hnear=&amp;ll=34.101624,-117.713914&amp;spn=0.00533,0.006437&amp;z=16&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?q=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hl=en&amp;cd=1&amp;ei=8483TIzUBYT2oATXufWPDQ&amp;sig2=lSwsnTqW0zOjJab9gRg87Q&amp;sll=34.101651,-117.713914&amp;sspn=0.006388,0.013937&amp;ie=UTF8&amp;view=map&amp;cid=6855595288345664401&amp;ved=0CEYQpQY&amp;hq=CLAREMONT+UNIVERSITY+CONSORTIUM&amp;hnear=&amp;ll=34.101624,-117.713914&amp;spn=0.00533,0.006437&amp;z=16&amp;iwloc=A&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>');

win.moveTo(200,200);
}
