// starting the script on page load
$(document).ready(function() {

  $("ul.marquee").marquee({ pauseSpeed: 0, scrollSpeed: 20 });

  $('.marker div.shadow').hide();
  $('#employment_container').hide();
  $('#special-features').hide();

  $('a.hotspot').tooltip({ track: true, delay: 0, fixPNG: true, showURL: false, showBody: " - ", fade: 200 });

  $('a.hotspot').hover(function() {
    //alert("url(Images/" + this.id + ".png) no-repeat;");
    $(this).stop().fadeTo('fast', 1);
  }, function() {
    $(this).stop().fadeTo('slow', 0);
  });

  $("form#contactform").validate();

  $('.marker').click(function() {

    $(".link").stop().animate({ "padding-left": "17px" }, { "duration": 200, "easing": "easeOutCirc" });
    $(".link").css({ "color": "#404040" });
    $("#link_" + this.id.substring(7, this.id.length)).css({ "color": "#E70000" });

    temp = this.id;
    jQuery.each($('.marker'), function() {
      if (this.id != temp) {
        $("#" + this.id + " div.shadow").stop().fadeOut(200).delay(200).hide();
      }
    });

    $('#' + this.id + ' div.shadow').stop().show().fadeIn(200);
		if(!($.browser.msie && $.browser.version.substr(0,1)<8) ){
      $('#cboxOverlay').stop().fadeTo(200, 0.3).show();
		}
  }).mouseover(function() {

    $(".link").stop().animate({ "padding-left": "17px" }, { "duration": 200, "easing": "easeOutCirc" });
    $(".link").css({ "color": "#404040" });
    $("#link_" + this.id.substring(7, this.id.length)).css({ "color": "#E70000" });

    /* ANIMATE SIZE OF MARKER*/
    $("#" + this.id + " img.icon").stop().animate({ "width": "38px", "height": "38px" }, { "duration": 200, "easing": "easeOutCirc" });

  }).mouseout(function() {
    $("#" + this.id + " img.icon").stop().animate({ "width": "20px", "height": "20px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $('#panel_contact ul li.link').click(function() {
    $('.marker div.shadow').stop().fadeOut({ easing: 'easeOutQuint', duration: 500 });
    $('#marker_' + this.id.substring(5, this.id.length) + ' div.shadow').stop().show().fadeIn(200);
    $('.marker img.icon').stop().animate({ "width": "20px", "height": "20px" }, { "duration": 200, "easing": "easeOutCirc" });
    $('#marker_' + this.id.substring(5, this.id.length) + " img.icon").stop().animate({ "width": "38px", "height": "38px" }, { "duration": 200, "easing": "easeOutCirc" });
    $('#panel_contact ul li.link').animate({ "padding-left": "17px" }, { "duration": 200, "easing": "easeOutCirc" });
    $('#panel_contact ul li.link').css({ "color": "#404040" });
    $(this).css({ "padding-left": "25px", "color": "#E70000" });
		
		if(!($.browser.msie && $.browser.version.substr(0,1)<8) ){
      $('#cboxOverlay').stop().fadeTo(200, 0.3).show();
		}
  });

  $(".link").mouseover(function() {
    $(this).stop().animate({ "padding-left": "25px" }, { "duration": 200, "easing": "easeOutCirc" });
    $('#marker_' + this.id.substring(5, this.id.length) + " img.icon").animate({ "width": "38px", "height": "38px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-left": "17px" }, { "duration": 200, "easing": "easeOutCirc" });
    $('#marker_' + this.id.substring(5, this.id.length) + " img.icon").animate({ "width": "20px", "height": "20px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $('a#employment').hover(function() {
    $(this).stop().animate({ "padding-bottom": "25px", "padding-top": "22px" }, { "duration": 200, "easing": "easeOutCirc" });
  }, function() {
    $(this).stop().animate({ "padding-bottom": "10px", "padding-top": "7px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $("#panel_company-updates ul li.link").hover(function() {
    $("div", this).slideDown({ "duration": 200, "easing": "easeOutCirc" });
  }, function() {
    $("div", this).slideUp({ "duration": 200, "easing": "easeOutCirc" });
  });

  $(".list_4 li ul li").mouseover(function() {
    $(this).stop().animate({ "padding-left": "25px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-left": "17px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $(".bttn_more").mouseover(function() {
    $(this).stop().animate({ "padding-right": "15px" }, { "duration": 200, "easing": "easeOutCirc" });
    $(this).css({ "background": "#262626 url(Images/arrow-right.gif) 40px center  no-repeat" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-right": "5px" }, { "duration": 200, "easing": "easeOutCirc" });
    $(this).css({ "background": "#00aeef" });
  });

  $('#cboxOverlay').click(function() {

    $(this).stop().fadeTo(200, 0).delay(200).hide();
    $('.marker div.shadow').fadeOut({ easing: 'easeOutQuint', duration: 500 });
    $('.link').css({ "color": "#404040" });

    //$('#employment_description').slideUp(200);
    //$('#employment_tab').slideDown(200);
    //$('#employment').css("border-bottom","1px solid #c4c4c4");

    $('#special-features').slideUp(200);
  });


  $('a.close').click(function() {
    $('#cboxOverlay').stop().fadeTo(200, 0).delay(200).hide();
    //$('#employment_description').slideUp(200);
    //$('#employment_tab').slideDown(200);
    //$('#employment').css("border-bottom","1px solid #c4c4c4");
    $('#special-features').slideUp(200);
  });

  $("#nav li a").click(function() {
    $("#nav li a").attr("class", "");
    $("#cboxOverlay").stop().fadeTo(200, 0).delay(200).hide();
    $(this).attr("class", "active");
  }).mouseover(function() {
    $(this).stop().animate({ "padding-top": "15px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-top": "5px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $("#employment").click(function() {
    $('#employment_rotator').cycle('destroy').cycle({
      fx: 'scrollHorz',
      speed: 200,
      timeout: 0,
      cleartype: true,
      easing: 'easeOutCirc',
      pager: '#pager'
    });

  });

  $("#logo img").mouseover(function() {
    $(this).stop().animate({ "padding-left": "10px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-left": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $("input.bttn").mouseover(function() {
    $(this).stop().animate({ "padding-left": "6px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "padding-left": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).focus(function() {
    $(this).stop().animate({ "padding-left": "6px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).blur(function() {
    $(this).stop().animate({ "padding-left": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  })

  $(".img_animate").mouseover(function() {
    $(this).stop().animate({ "bottom": "-10px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "bottom": "-20px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).click(function() {
    $("#cboxOverlay").stop().fadeTo(200, 0).delay(200).hide();
  });

  $(".list_4 li h3").mouseover(function() {
    $(this).stop().animate({ "margin-bottom": "0px", "margin-top": "-5px" }, { "duration": 200, "easing": "easeOutCirc" });
  }).mouseout(function() {
    $(this).stop().animate({ "margin-bottom": "-" + ($("#" + $(this).parent().attr("id") + " p").height() + 25) + "px", "margin-top": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

	$(".showfeatures").click(function() {	
	  if($('#special-features').length > 0 ){
		  $('#special-features').slideDown(200);
		  if(!($.browser.msie && $.browser.version.substr(0,1)<8) ){
		    $('#cboxOverlay').stop().fadeTo(200, 0.3).show();
		  }
		}
	});
	
	$("div.special-features-info a").click(function(){
		$("input#username").focus();
	});

  $("div#panel_company-updates a#more").click(function() {
    $(this).hide();
    $("div#panel_company-updates a#less").show();
    $("div#panel_company-updates ul").stop().animate({ "height": $("div#panel_company-updates ul").children().size() * 27 + "px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $("div#panel_company-updates a#less").click(function() {
    $(this).hide();
    $("div#panel_company-updates a#more").show();
    $("div#panel_company-updates ul").stop().animate({ "height": "81px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $('#reset_captcha').click(function() {
    $('#captcha').attr('src', $('#captcha').attr('src') + 1);
  });

  // COLORBOX
	$('a.lightbox').colorbox({iframe:true, width:"800", height:"80%", transition:'elastic', speed:200, opacity:.3});
	$('a.pdf').colorbox({ iframe:true, width:"1000", height:"80%", transition:'elastic', speed:200, opacity:.3});
	$('a#employment').colorbox({ inline: true, href:"#employment_description", width:"550", transition:'elastic', speed:200, opacity:.3});

  $('.special-feature h4').click(function() {

    if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
      $('.special-features-info').hide();
      $(this).siblings().show();
    }
    else {
      $('.special-features-info').slideUp(200);
      $(this).siblings().slideDown(200);
    }


    if (!($.browser.msie && $.browser.version.substr(0, 1) < 9)) {
      $('.special-features-info img').animate({ "margin-top": "0px" }, { "duration": 200, "easing": "easeInCirc" });
      $(this).siblings('.special-features-info').children('img').animate({ "margin-top": "-25px" }, { "duration": 200, "easing": "easeInCirc" });
    }

  }).hover(function() {
    $(this).stop().animate({ "padding-left": "10px" }, { "duration": 200, "easing": "easeOutCirc" });
  }, function() {
    $(this).stop().animate({ "padding-left": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  $('h3 a').hover(function() {
    $(this).stop().animate({ "padding-left": "10px" }, { "duration": 200, "easing": "easeOutCirc" });
  }, function() {
    $(this).stop().animate({ "padding-left": "0px" }, { "duration": 200, "easing": "easeOutCirc" });
  });

  function showLoading() { $("#loading img").fadeIn({ duration: 500, easing: "easeOutCirc" }); }
  function hideLoading() { $("#loading img").fadeOut({ duration: 500, easing: "easeOutCirc" }); }

  $("#submit").click(function() {
    var invalidCode = "<p><strong>Invalid code.</strong></p>";

    if ($("#contactform").valid()) {
      showLoading();

      $.ajax({
        type: "POST",
        async: true,
        url: "/index.aspx",
        data: $("#contactform").serialize(),        
        dataFilter: function(data) {
          var msg = eval('(' + data + ')');

          if (msg.hasOwnProperty('d'))
            return msg.d;
          else
            return msg;
        },
        success: function(response) {
          hideLoading();
          var res = (typeof response) == 'string' ? eval('(' + response + ')') : response;

          res.responseType === "redirect" ? window.location.href = res.response :
                          function() {
                            eval($("#rcContact a.rcRefreshImage").attr('href'));
                            hideLoading();
                            $("#errorbox").html(res.response); $.fn.colorbox({ inline: true, href: "#errorbox", width: "200", height: "100", transition: 'elastic', speed: 300, opacity: .3 });
                          } ();
        },
        error: function(jqXHR, textStatus, errorThrow) {
          hideLoading();
          $("#errorbox").html(occurred);
          $.fn.colorbox({ inline: true, href: "#errorbox", width: "200", height: "100", transition: 'elastic', speed: 300, opacity: .3 });
        }
      });

      return false;
    }
  });
});
