﻿//Homepage carousel 
var mycarousel_itemList = [
    { url: "images/carousel/carousel_image1.jpg", alt: "Range Rover - Go Beyond", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/0/zHr27cia71g" },
    { url: "images/carousel/carousel_image_a.jpg", alt: "Sustainable Future", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/1/DzLUom41sqo" },
    { url: "images/carousel/carousel_image5.jpg", alt: "Jaguar XJ Video", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/4/gLgyK2UCCxI" },
    { url: "images/carousel/carousel_image_b.jpg", alt: "Apprentice Profile - Charlotte Barnes", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/2/SKhe8tSnm_c" },
    { url: "images/carousel/carousel_image3.jpg", alt: "LRX - Behind the Scenes", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/2/thYL0l89M5g" },
    { url: "images/carousel/carousel_image_c.jpg", alt: "Development Event", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/0/zxP5r-wWhK0" },
    { url: "images/carousel/carousel_image4.jpg", alt: "Jaguar XJ Reveal Video", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/3/6Wsrc7Sb_8k" },
    { url: "images/carousel/carousel_image2.jpg", alt: "Freelander 2 TD4 Launch", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/1/5BrLsW4vqQI" },
    { url: "images/carousel/carousel_image6.jpg", alt: "XJ Launch Video", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/5/2L8jeuLDTX4" },
    { url: "images/carousel/carousel_image7.jpg", alt: "XF Launch Video", clickthro: "http://www.youtube.com/poweredbypeople1#play/uploads/6/2lOBYZzwA-U" }
];

//Youtube dropdown - The Experience
function yt_drop_down(){
    $("ul#yt_drop_down").css('display','none');
    $("#link_list span").click(function(){ 
        $("ul#yt_drop_down").toggle();
    });
    $("ul#yt_drop_down a").click(function(){ 
        $("#playlist h2").html("");
        $("#playlist h2").append($(this).text());
        $("ul#yt_drop_down").css('display','none');
    });
}

function mycarousel_itemLoadCallback(carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }
        if (i > mycarousel_itemList.length) {
            break;
        }
        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i - 1]));
    }
};


function mycarousel_getItemHTML(item) {
    return '<a href="' + item.clickthro + ' " target="_blank" title="Opens the Jaguar Land Rover Careers YouTube channel in a new window"><img src="' + item.url + '" width="280" height="157" alt="' + item.alt + ' - Opens the Jaguar Land Rover Careers YouTube channel in a new window" /><br />' + item.alt + '</a>';
};


function homePageCarousel() {    
    jQuery('#JLRcarousel').jcarousel({
    size: mycarousel_itemList.length,
    scroll: 3,
    easing: "swing",
    wrap: "last",
    animation: "2", 
    itemLoadCallback: { onBeforeAnimation: mycarousel_itemLoadCallback }
    });
}

//Work out if ie6 is being used...if so use the window object when dealing with flash rather than the document object
function getFlashMovie(movieName) {
       return document[movieName];

}

//This function is fired by actionscript when the profiles swf is ready.
//It sets allowclick to true - which allows the user to interact with ther flash movie via html
var allowclick = false
function playerResponsive() {
    allowclick = true;   
}

//Profiles communcation between the leftnav and the flash - All of the comms on in this file pretty much follow this procedure...give or take a few modifications 
function profilesFlashComm() {
    //hide the nested un-ordered list - first step in creating the accordion effect
    $('#leftColumn ul li ul').hide();
    //Select the top level links - but dont select the nested links
    var topLevelLinks = $('#leftColumn ul li a').not('#leftColumn ul li ul li a');
    //Stop the top level links from following the link in their href attribute
    topLevelLinks.bind("click",function() {
        return false;
    });
    //now listen for clicks on the top level links
    topLevelLinks.bind("click", function() {
        //Remove the active class all the top level links
        $('#leftColumn ul li a').removeClass('active');
        //apply the active class to the link that's just been clicked on
        $(this).addClass('active');
        //Slide up any open nested lists - next step in the accordion effect 
        $('#leftColumn ul li ul').slideUp();
        //grab the parent <li> element of the link that's just been clicked on
        var li = $(this).parent();
        //Find the <ul> that is a prent of the <li> we just selected and slide it down - last step of the accordion
        var r = li.find('ul').slideDown();
    });
    
    //now create a refrence to the links in the nested <ul>
    var links = $('#leftColumn ul li ul li a');
    //Again disable default behaviour
    links.bind("click",function() {
        return false;
    });
    //Create an array with all the aspx filenames in minus the .aspx part
    var names =  ['ChrisMann','ClaireFreeman','AndrewHamilton','TomBury', 'MatiasFuentasMattioli', 'BenRothary', 'AmirAlemohammed'];
    //listen for clicks on the nested level links
    links.bind("click", function() {
        //for loop - keep going until all the entries in the names array have been iterated over
        for (var i = 0; i < names.length; ++i) {
            //if Allowclick is set to true see playerResponsive() above.
            if (allowclick) {
                //show the transcript buttons
                $('#profileLinks').show();
                //empty the rightcolumn div ready for the video and transcript
                $('#rightColumnInner #intro').empty();
                //If there's a match between the href string of link that's been clicked on and the names array...
                if (this.href.indexOf(names[i]) !== -1) {
                    //remove any class of active on links in the nested <ul>
                    $('#leftColumn ul li ul li a').removeClass('active');
                    //send to flash the path to the flv
                    getFlashMovie('flashcontent').sendToActionscript('flv/profiles/' + names[i] + '.mp4');

                    //apply a class of active to the link that's jst been clicked on
                    $(this).addClass('active');
                    //function to send deal with content being sent to the webservice  
                    function GotContent(results) {
                        $('#transcript').empty();
                        $('#transcript').append(results);
                    }
                    //send a string of the path to the transcript content to the webservice
                    if (i == 0 || i == 1) {
                         $('#transcript').empty();
                         $("#transcript").load("Graduate/" + names[i] + ".aspx #content"); 
                        //GetContent.GetProfile("Graduate/" + names[i] + ".aspx", GotContent);
                    } else {
                     $('#transcript').empty();
                         $("#transcript").load("Experienced/" + names[i] + ".aspx #content"); 
                        //GetContent.GetProfile("Experienced/" + names[i] + ".aspx", GotContent);
                    }
                }
            }
        }
    });
}


//setup and control the show/hide transcript buttons
function transcriptButtons() {
    var buttons = $('#profileLinks a');
    buttons.click(function() {
        if(this.id == 'show') {
            $('#transcript').show();
            //send message to flash to pause
             getFlashMovie('flashcontent').sendPauseToFlash();
            $('a#show').hide();
            $('a#hide').show();  
        } else if(this.id == 'hide') {
            $('#transcript').hide();
            //send message to flash to resume
             getFlashMovie('flashcontent').resumeFlash();
            $('#hide').hide();  
            $('#show').show(); 
        }
    });
}


//Opportunities Flash Comm
function opportunitiesFlashComm() {
    $('#leftColumn ul li ul').hide();
    var currentlySelected = '';
    var sections = ['Graduates','ExperiencedHires','Apprentices','Undergraduates'];
    var sectionMappings =  ['grads','exhires','apprentices','undergrads'];
    var links = $('#leftColumn ul li a').not('#leftColumn ul li ul li a');
    links.bind("mouseover",function() {
        if(allowclick) {
            for(var i=0; i<sections.length; ++i) {
                if(this.href.indexOf(sections[i]) !== -1) {
                    getFlashMovie('flashcontent').clipForward(sectionMappings[i]);
                    currentlySelected = sectionMappings[i];
                }
            }
        }         
    });
    
    links.bind("mouseout",function() {
        if(allowclick) {
            getFlashMovie('flashcontent').clipReverse(currentlySelected);
        }         
    });
     
    links.click(function() {
        return false;
    });
     
    links.click(function() {
        $('#leftColumn ul li a').removeClass('active');
        $(this).addClass('active');
        $('#leftColumn ul li ul').slideUp();
        var li = $(this).parent();
        var r = li.find('ul').slideDown();
        for(var i=0; i<sections.length; ++i) {
            if(this.href.indexOf(sections[i]) !== -1) {
                var target =  sections[i] + '/Default.aspx #content';
                $("#rightColumnContent").load(target);
            }
        }
    });
}


//Opportunities flash Comm - inner sub level pages
function opportunitiesInnerFlashComm() {
    $('#leftColumn ul li ul').hide();
    var activeList = $('#leftColumn ul li a.active').parent().find('ul').show();
    var topLevelLinks = $('#leftColumn ul li a').not('#leftColumn ul li ul li a');
    topLevelLinks.bind("click",function() {
        return false;
    });
    topLevelLinks.bind("click", function() {
        $('#leftColumn ul li ul').slideUp();
        $('#leftColumn ul li a').removeClass('active');
        $(this).addClass('active');
        var li = $(this).parent();
        li.find('ul').slideDown();

    });
}


//Working with us flash comm
function WorkingWithUsFlashComm() {
    $('#leftColumn ul li ul').hide();
    var topLevelLinks = $('#leftColumn ul li a').not('#leftColumn ul li ul li a');
    topLevelLinks.bind("click",function() {
        return false;
    });
    topLevelLinks.bind("click", function() {
        getFlashMovie('flashcontent').endVideo('blah');
        var topLevelSections = ['Culture','Vision','Projects','CareerDevelopment'];
        $('#leftColumn ul li ul').slideUp();
        $('#leftColumn ul li a').removeClass('active');
        $(this).addClass('active');
        var li = $(this).parent();
        li.find('ul').slideDown();
         for(var i=0; i<topLevelSections.length; ++i) {
                if(this.href.indexOf(topLevelSections[i]) !== -1) {
                  var target =  topLevelSections[i] + '/Default.aspx #content';
                $("#rightColumnContent").load(target);           
                }
         }        
    });
    var links = $('#leftColumn ul li ul li a');
    var sections = ['Culture','Vision','Projects','CareerDevelopment'];
    var sectionMappings = ['culture', 'our vision', 'projects','career development'];
    topLevelLinks.bind("mouseover",function() {
        if(allowclick) {
            for(var i=0; i<sections.length; ++i) {
                if(this.href.indexOf(sections[i]) !== -1) {
                    //hide this??
                    //getFlashMovie('flashcontent').endVideo('blah');
                    getFlashMovie('flashcontent').hotspotOver(sectionMappings[i]);
                }
            }
        }
    });
    
    topLevelLinks.bind("mouseout",function() {
        if(allowclick) {
            getFlashMovie('flashcontent').hotspotOut('blah');
        }
    });
    
    links.bind("click",function() {
        $(this).removeClass('active');
        return false;
    });

    links.bind("click", function() {

        if (allowclick) {

            for (var i = 0; i < sections.length; ++i) {
                if (this.href.indexOf(sections[i]) !== -1) {
                    var spliturl = this.href.split(sections[i] + '/');
                    $('#leftColumn ul li ul li a').removeClass('active');
                    $(this).addClass('active');
                    //hide this??
                    //getFlashMovie('flashcontent').endVideo('blah');
                    var target = sections[i] + '/' + spliturl[1] + ' #content';
                    $("#rightColumnContent").load(target);
                    if (spliturl[1] == 'AwardWinning.aspx') {
                        getFlashMovie('flashcontent').spawnMiniPlayer('Mp4/awards.mp4'); 
                        $("#rightColumnContent").load('Projects/AwardWinning.aspx #videoBuffer');
                    } else if (spliturl[1] == 'Future.aspx') {
                      getFlashMovie('flashcontent').spawnMiniPlayer('Mp4/vr_centre.mp4');
                        $("#rightColumnContent").load('Projects/Future.aspx #videoBuffer');
                    } else if (spliturl[1] == 'MakingADifference.aspx') {
                        getFlashMovie('flashcontent').spawnMiniPlayer('Mp4/g4_challenge.mp4');
                        $("#rightColumnContent").load('Projects/MakingADifference.aspx #videoBuffer');
                    } else if (spliturl[1] == 'Sustainable.aspx') {
                        getFlashMovie('flashcontent').spawnMiniPlayer('Flv/environment.flv');
                        $("#rightColumnContent").load('Projects/Sustainable.aspx #videoBuffer');
                    } else if (spliturl[1] == 'Interior.aspx') {
                        getFlashMovie('flashcontent').spawnMiniPlayer('Flv/Interior.flv');
                        $("#rightColumnContent").load('Projects/Interior.aspx #videoBuffer');
                    }
                }
            }

        }
        $('a:contains("One High Performance")').click(function() {
            window.open("../imagePopup.html", "HiPerformance", "width=960,height=400");
        });
    });
}


//Locations Flash Comm - google maps code included
function LocationsFlashComm() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(54.481383, -2.982031), 5);
        map.addControl(new GSmallMapControl());
        map.setMapType(G_SATELLITE_MAP) 
    }
    var topLevelLinks = $('#leftColumn ul li a').not('#leftColumn ul li ul li a');
    var sections = ['Gaydon','Halewood','Solihull','Whitley','BrownsLane','CastleBromwich'];
    var locationsLat = ['52.19464','53.354323','52.436878','52.384596','52.433246','52.514092'];
    var locationsLng = ['-1.484434','-2.831469','-1.780913','-1.490644','-1.561053','-1.800747'];
    var sectionMappings = ['gd','hw','sh','wl','bl','cb'];  
    topLevelLinks.bind("click",function() {
        return false;
    });
    topLevelLinks.bind("click",function() {
        
        for(var i=0; i<sections.length; ++i) {
            if(this.href.indexOf(sections[i]) !== -1) {
                 if(allowclick) {
                        var topLevelLinks = $('#leftColumn ul li a').removeClass('active');
                        $(this).addClass('active');
                        getFlashMovie('flashcontent').sendLocationToFlash('flv/'+sectionMappings[i]+'.flv'); 
                        var point = new GLatLng(locationsLat[i],locationsLng[i]);
                        var target =  sections[i]+'.aspx #content';
                        $("#rightColumnContent #siteInfo").load(target);
                        var marker = new GMarker(point); 
                        map.clearOverlays();
                        map.addOverlay(marker);
                        map.panTo(new GLatLng(locationsLat[i],locationsLng[i]));
                       
                }
            }
        }
    });
}

//hall of fame code...send id's from the leftnav to the flash movie
function HallofFameFlashComm() {
    var thumbs = $('#playlist ul li a');
    thumbs.click(function() {
    var id = this.id;
        getFlashMovie('player').sendYoutubeVid(id);
    });
}

//hall of fame touch area - send id's from the leftnav to the flash movie
function jlrExperienceTouchComm() {
    var links = $('#leftColumn ul li a');
    links.bind("click", function() {
        return false;
    });
    links.bind("click", function() {
        var sections = ['GreenPowerCorp','GreenChainEvents','GreenRangeSecuresHalewood','MakingPlans','TopGearPart1','TopGearPart2','TopGearPart3','TopGearPart4'];
        var videosections = ['TopGearPart1.aspx','TopGearPart2.aspx','TopGearPart3.aspx','TopGearPart4.aspx'];
        var videoids = ['WjnkM9Ws9Fw','w-y1oi1hTgw','Ny9iEE71tGE','hNv5pyUSkso'];
        for(var i=0; i<sections.length; ++i) {
        getFlashMovie('flashcontent').endVideo('blah');
            $('#leftColumn ul li a').removeClass('active');
            $(this).addClass('active');
            if(this.href.indexOf(sections[i]) !== -1) {
                if(this.href.indexOf('/Video/') !== -1) {
                     var target =  'Video/' + sections[i]+'.aspx #VideoContent';
                } else {
                    var target =  sections[i]+'.aspx #content';
                }
                $("#rightColumnContent").load(target);   
            }
        }
        for(var i=0; i<videosections.length; ++i) {
            if(this.href.indexOf(videosections[i]) !== -1) {
                $('#rightColumnInner, #content').hide();
                getFlashMovie('flashcontent').sendYoutubeVid(videoids[i]);
            }
        }
    });
}

function eventsFlashComm() {
    var links =  $('#leftColumn ul li a');
    var sections = ['February'];
    links.bind("click" ,function() {
        return false;
    })
    links.bind("click" ,function() {
         for(var i=0; i<sections.length; ++i) {  
            if(this.href.indexOf(sections[i]) !== -1) {
              $('#leftColumn ul li a').removeClass('active');
            $(this).addClass('active');
               var target =  sections[i]+'.aspx #content';
                $("#rightColumnContent").load(target);     
            }
         } 
    });
}

function FAQSFlashComm() {
    if(location.href.indexOf('referer=faq') != -1) {
        $('ul#TopNavigation li a').removeClass('active');
        $('ul#TopNavigation li a:last').addClass('active');   
    }
    var links = $('#leftColumn ul li a');
    links.bind("click", function() {
        return false;
    });
    links.bind("click", function() {
    var sections = ['ExperiencedHires','Graduates','Apprentices','Undergrads','Hints'];
      $('#leftColumn ul li a').removeClass('active');
            $(this).addClass('active');
             for(var i=0; i<sections.length; ++i) {  
            if(this.href.indexOf(sections[i]) !== -1) {
             var target =  sections[i]+'.aspx #content';
                $("#rightColumnContent").load(target);  
            }
            
            }
    });
}


 
        





    
   





