/* Author: 

 */
function rotateImages($id) {
  var oCurPhoto = $('#' + $id + ' div.current');
  var oNxtPhoto = oCurPhoto.next();
  if(oNxtPhoto.length == 0)
    oNxtPhoto = $('#' + $id + ' div:first');

  oCurPhoto.removeClass('current').addClass('previous');

  oNxtPhoto.css({opacity:0.0}).addClass('current').animate({opacity:1.0}, 1000,
      function() {
        oCurPhoto.removeClass('previous');
      });
}

$(function() {
  // Rotate images
  setInterval("rotateImages('headerSlide')", 5000);


  // Start clouds moving
  $('body').bgscroll({scrollSpeed:90 , direction:'h' });


  // Remove last border in main nav
  $('#main_nav ul li a:last').css('border', '0px');

  // Highlight group add-ons rows
  $(".pricing tr").hover(
      function() {
        $(this).addClass("highlightRow");
      },
      function() {
        $(this).removeClass("highlightRow");
      }
  );


  // Social networking icons
  $('#facebook').mouseover(function() {
    social_icons('Facebook');
  }).mouseout(function() {
    social_icons('');
  });

  $('#twitter').mouseover(function() {
    social_icons('Twitter');
  }).mouseout(function() {
    social_icons('');
  });

  $('#myspace').mouseover(function() {
    social_icons('Myspace');
  }).mouseout(function() {
    social_icons('');
  });

  $('#flickr').mouseover(function() {
    social_icons('Flickr');
  }).mouseout(function() {
    social_icons('');
  });

  $('#photobucket').mouseover(function() {
    social_icons('Photobucket');
  }).mouseout(function() {
    social_icons('');
  });

  $('#virtualtour').mouseover(function() {
    social_icons('Virtual Tour');
  }).mouseout(function() {
    social_icons('');
  });

  $('#youtube').mouseover(function() {
    social_icons('YouTube');
  }).mouseout(function() {
    social_icons('');
  });

  function social_icons(site) {
    var name = '#socialName';
    var panel = '#socialPanel'
    $(name).text(site);

    /*
    var width = $('#panel').css('width');
    if(site != '') {
      $(panel).animate({
        width: '+=100'
      }, 500);

      //$('#panel').css('width', '+=100');
    } else {
      $(panel).animate({
            width: '-=100'
          }, 500);

      //$('#panel').css('width', '-=100');
    }
    */
  }


  // Balloons and groups animation
  $('#bday1').hover(function() {
    bday(1);
  });

  $('#bday2').hover(function() {
    bday(2);
  });

  $('#bday3').hover(function() {
    bday(3);
  });

  $('#bday4').hover(function() {
    bday(4);
  });

  function bday(num) {
    var elem = '#bday' + num;
    var bday_offset = $(elem).offset();
    $(elem).offset(bday_offset);

    $(elem).animate({
          width: '0',
          height: '0',
          top: '-=500'
        }, 5000, function() {
          $(elem).removeAttr('style');
        });
  }

  $('#group1').click(function() {
    group(1);
  });
  $('#group2').click(function() {
    group(2);
  });
  $('#group3').click(function() {
    group(3);
  });
  $('#group4').click(function() {
    group(4);
  });
  $('#group5').click(function() {
    group(5);
  });
  $('#group6').click(function() {
    group(6);
  });
  $('#group7').click(function() {
    group(7);
  });

  function group(num) {
    var elem = '#group' + num;
    var group_offset = $(elem).offset();
    $(elem).offset(group_offset);

    $(elem).animate({
          top: '+=15'
        }, 300, function() {
          $(elem).removeAttr('style');
        });
  }
});
