//calash.js - jquery scripts for Calash website
//
// Author: Stuart Malcolm
// Email: stuart@ifoundry.co.uk
// Created: 10 Feb 2011
//


function HomePageSlideShow() {
    var $active = $('#home-banner IMG.active');

    if ( $active.length == 0 ) $active = $('#home-banner IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#home-banner IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}//slideShow

//--------------------------------------------------------------------

function TestimonialsSlideShow() {
    var $active = $('#testimonials div.active');

    if ( $active.length == 0 ) $active = $('#testimonials div:last');

    var $next =  $active.next().length ? $active.next()
        : $('#testimonials div:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}//slideShow


//--------------------------------------------------------------------

$(function() {
    setInterval( "HomePageSlideShow()", 5000 );  // Set the timing of homepage slideshow (milliseconds)
    setInterval( "TestimonialsSlideShow()", 15000 );  // Set the speed of TESTIMONIALS animation (milliseconds)

    //fortune-wheel setup
    $('#fortune-wheel-map area').hover(
      //when mouse hovers over the fortune wheel image map areas,
      //set the position of the background image that is 'under' the imagemap
      function(e){
        var hreftag = $(this).attr('href');
        var bgpos = '0 0';
        switch (hreftag)
        {
          case '#feedback':     	bgpos = '-420px 0'; break;
          case '#operations':    bgpos = '-840px 0'; break;
          case '#contracts':     bgpos = '-1260px 0'; break;
          case '#range':  			bgpos = '-1680px 0'; break;
          case '#quality':  		bgpos = '-2100px 0'; break;
          case '#technology':   	bgpos = '-2520px 0'; break;
          case '#market':        bgpos = '-2940px 0'; break;
          case '#growth':      	bgpos = '-3360px 0'; break;
          case '#projections':  	bgpos = '-3780px 0'; break;
          case '#management':   	bgpos = '-4200px 0'; break;
        }//switch
        //now, set the background image position
        $('#fortune-wheel').css('background-position',bgpos);
        //and display the pop-up window
//        $("#popup").css("left",(e.pageX) + "px").css("top",(e.pageY - $("#popup").height()) + "px").show();
        $(hreftag+'-popup').show();
        $("#popup").stop().fadeTo("slow",0.9);
      },
      //when mouse hovers off, return the background position to default
      function(){
        $('#fortune-wheel').css('background-position','0 0');
        $("#popup").stop().fadeTo("fast",0.0);
        $("#popup div").hide();
      }
    ); //fortune-wheel-map hover
    
  //when the mouse moves over a fortune-wheel area..
  $('#fortune-wheel-map area').mousemove(function(e){
    //move the popup based on the mouse position
    $("#popup").css("left",(e.pageX+15) + "px").css("top",(e.pageY - $("#popup").height()-15) + "px");
  })

  //setup the imagemap highlighting    
  $('#business-growth img').maphilight({
      fillColor: '559cbe', 
      fillOpacity: '1',
      fade: false, 
      stroke: false      
  });

  $('#business-growth area').hover(
     function(){
        var hreftag = $(this).attr('href');
        $("#popup").stop().fadeTo("slow",0.9);
        $(hreftag+'-popup').show();
     },
     function(){
        $("#popup").stop().hide();
        $("#popup div").hide();
     }
  );

  //when the mouse moves over a business growth map area..
  $('#business-growth area').mousemove(function(e){
    //move the popup based on the mouse position
    $("#popup").css("left",(e.pageX+15) + "px").css("top",(e.pageY - $("#popup").height()+100) + "px");
  })

});

