//To avoid conflict with other libraries (MooTools in that case)
jQuery.noConflict();

pageID = "";
/*================================================== JAVASCRIPT */
/*
*/
//Apply the Javascript-enabled styles (hidding expandable boxes for instance)
jQuery('html').addClass('js'); 

//Global variables
popup_motion = true;
popup_motion_speed = 150;
popup_motion_offset = 4;
popup_position_offset_top = 140;

expand_speed = 250;

jQuery(document).ready(function() {
     
    // Fix IE6 background image caching problem
    if (jQuery.browser.msie) {
        try { 
            document.execCommand("BackgroundImageCache", false, true); 
        } catch(err) {}
    }
    
	if(jQuery.client.os == "Mac" && jQuery.client.browser == "Firefox"){
		popup_position_offset_top = 150;
	}


    //dropdown navigation support for IE6, hover class
    jQuery('#graduates_content_container #navigation_dropdown ul li.headlink').hover(function() { 
        jQuery('ul', this).css('display', 'block'); 
    },function() { 
        jQuery('ul', this).css('display', 'none'); 
    });

    //--------------------------------------------- Initialization
    UpdateNavigation();
    InitThumbPopup();
    InitExpandableModules();    
    jQuery("#accordion").accordion({ active: false, collapsible: true, autoHeight: false });
    jQuery('a.expand_link').click(function(){ 
        return false; 
    });    
    
	jQuery('table.striped tbody tr:nth-child(even)').addClass('strip');
});

function UpdateNavigation()
{
    if(pageID != ""){    
        jQuery("#graduatesnav #" + pageID).addClass("on");
    }
}

//--------------------------------------------- THUMBNAIL POPUP
function InitThumbPopup(){
    jQuery('#thumb_list a').each(function(){
        var link = jQuery(this);
        var title = jQuery(this).attr('title');
        var linkId = jQuery(this).parent().attr('id').split('thumb_')[1];
        var name = title.split(' - ')[0];
        var sector = title.split(' - ')[1];
        
        if(linkId == profileID){
            link.addClass('current');        
        }
        
        //Add the popup into the thumb link
        jQuery(this).empty();
        jQuery(this).append('<span><strong>' + name + '</strong> - ' + sector + '</span>');
                
        var popup = jQuery(this).find('span');
        
        popup.css('top', link.offset().top - popup_position_offset_top);
        popup.css('left', link.offset().left - 12);
    });  
    
    jQuery('#thumb_list a').hover(function(){
            var popup = jQuery(this).find('span');            
            
            popup.show();            
            if(popup_motion){
                popup.animate({
                    top: popup.position().top - popup_motion_offset
                },
                popup_motion_speed);    
            }
        }, function(){
            var org_top_offset = jQuery(this).offset().top - popup_position_offset_top;
            var popup = jQuery(this).find('span');
            
            if(popup_motion){
                popup.stop().css('top', org_top_offset);
            }
            popup.hide();
    });     
}

//--------------------------------------------- EXPANDABLE MODULES	
function InitExpandableModules() {
    jQuery("#expandable a.expand_link").click(function() {
        var link = jQuery(this);
        var org_link_classes = link.attr('class').split('opened')[0].split('closed')[0];
        var module_holder = jQuery(this).find("+ div.expand_content");                
        
        //console.log(org_link_classes);

        module_holder.slideToggle(expand_speed, function() {            
        
            if (link.hasClass('closed')) {
                //if the module was CLOSE and is OPENING
                link.attr('class', org_link_classes + ' opened');                                                                
            } else {
                //if the module was OPEN and is CLOSING
                link.attr('class', org_link_classes + ' closed');                
            }
        });
        jQuery(this).toggleClass('close');
        jQuery(this).toggleClass('open');

        return false;
    });
}

//--------------------------------------------- HIGHSLIDE

    // d7044f26ee357206e920ffb9b282f0f5
    hs.graphicsDir = '/graduates/shared/highslide/graphics/';
	hs.wrapperClassName = 'wide-border';
	hs.showCredits = false;
	hs.allowMultipleInstances = false;
	hs.fadeInOut = true;





