jQuery(document).ready(function($){
    //swap logo text on home page
    //$('body.home #logoimg').attr("src", "/wp-content/themes/ckg/images/logo.gif");
    
    $("a[href^='http://']").each(function(){
        var thehref = $(this).attr('href');
        if(thehref.match(window.location.host)){
        //do nothing
        } else {
            $(this).attr('target', '_blank');
        }
    });

    //back to top
    $('#back_to_top').click(function(){
        jQuery('html,body').animate({
            scrollTop: '0'
        }, 1000);
    });

    //remove the long title desc from link hovers
    $('#sidenav a').hover(function(){
        $(this).attr('title', '');
    });
    //Create the image map
    if($('#marquee img').length){
        var marquee_src = $('#marquee img').attr('src');
        if(marquee_src.match('header_services')){
            var assesment = '<a href="http://www.compassknowledge.com/e-learning-services/assessment-of-successful-online-program/" id="assesment_link" class="serv_map">Assessment</a>';
            var financing = '<a href="http://www.compassknowledge.com/e-learning-services/financing-online-programs/" id="financing_link" class="serv_map">Financing</a>';
            var marketing = '<a href="http://www.compassknowledge.com/e-learning-services/higher-education-marketing/" id="marketing_link" class="serv_map">Marketing</a>';
            var recruitment = '<a href="http://www.compassknowledge.com/e-learning-services/student-recruitment/" id="recruitment_link" class="serv_map">Recruitment</a>';
            var curriculum = '<a href="http://www.compassknowledge.com/e-learning-services/distance-learning-course-development/" id="curriculum_link" class="serv_map">Curriculum and Course Development</a>';
            var design = '<a href="http://www.compassknowledge.com/e-learning-services/instructional-design-and-technology/" id="design_link" class="serv_map">Instructional Design and Technology</a>';
            var faculty = '<a href="http://www.compassknowledge.com/e-learning-services/faculty-support-and-training/" id="faculty_link" class="serv_map">Faculty Support and Training</a>';
            var manage = '<a href="http://www.compassknowledge.com/e-learning-services/manage-online-learning-environments/" id="manage_link" class="serv_map">Manage the Online Learning Environment</a>';
            var retention = '<a href="http://www.compassknowledge.com/e-learning-services/student-retention/" id="retention_link" class="serv_map">Student Retention</a>';
            var competitiveness = '<a href="http://www.compassknowledge.com/e-learning-services/distance-learning-partnership-development/" id="competitiveness_link" class="serv_map">Plan for Increasing Competitiveness</a>';

            $('#marquee').prepend(assesment);
            $('#marquee').prepend(financing);
            $('#marquee').prepend(marketing);
            $('#marquee').prepend(recruitment);
            $('#marquee').prepend(curriculum);
            $('#marquee').prepend(design);
            $('#marquee').prepend(faculty);
            $('#marquee').prepend(manage);
            $('#marquee').prepend(retention);
            $('#marquee').prepend(competitiveness);
        }
    }

    //open pdfs in new tab
    $('#content a[href^="http://"], #content-full a[href^="http://"], #rightbar a[href^="http://"]').each(function(){
        thehref = $(this).attr('href');
        theext  = thehref.split('.').pop().toLowerCase();
        if(theext == 'pdf'){
            $(this).attr('target', '_blank');
        }
    });

    $('a[rel="pop"]').click( function() {
        window.open( $(this).attr('href'),'name','height=360,width=500,toolbar=no,modal=yes,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
        return false;
    });

    $('#content-full div.oldnews').css('display', 'none');

    $('#content-full div.currentnews:last').after('<a id="morenews">See Older News</a>');

    $('#morenews').toggle(function(){
        $('#content-full div.oldnews').css('display', 'block');
    }, function(){
        $('#content-full div.oldnews').css('display', 'none');
    });

    //hack to swap misbehaving sidenav ordering
    var consultingServices = $("#sidenav ul.children li a:contains('Consulting')").parent();
    var partnershipWorks = $("#sidenav ul.children li a:contains('Partnership')").parent();
    consultingServices.insertBefore(partnershipWorks);

								
});