/**
 * Created by Nan on 2014/7/10.
 */
;
(function(window, $) {
  function init() {
    bindEvt();
  }
  init();

  function bindEvt() {
    var $eachval = false;
    //迴圈跑#FriendLin    
    $('.FriendLink').each(function(i) {
      $("#" + $(this).attr("id") + "").bind("change", function() {
        var selectedHref = $("#" + $(this).attr("id") + " :selected").val();
        if (selectedHref != "") {
          window.open(selectedHref, '_self');
        }
      });
      $eachval = true;
    });
    //舊版待廢除
    if ($eachval == false) {
      $("#FriendLink").bind("change", function() {
        var selectedHref = $("#FriendLink :selected").val();
        if (selectedHref != "") {
          window.open(selectedHref, '_self');
        }
      });
      $("#FriendLink1").bind("change", function() {
        var selectedHref = $("#FriendLink1 :selected").val();
        if (selectedHref != "") {
          window.open(selectedHref, '_self');
        }
      });
      $("#FriendLink2").bind("change", function() {
        var selectedHref = $("#FriendLink2 :selected").val();
        if (selectedHref != "") {
          window.open(selectedHref, '_self');
        }
      });
    }
    $(".nav li").hover(navLiMouseOver, navLiMouseOut);
  }

  function navLiMouseOver() {
    $(this).parent().parent().find("li").removeClass("hov");
    $(this).addClass("hov");
  }

  function navLiMouseOut() {
    $(".nav li").removeClass("hov");
  }
  //Set SearchInput
  $("#searchForm").children(':text').focus(function() {
    if (!this.initValue) {
      this.initValue = this.value;
    }
    if (this.value === this.initValue) {
      this.value = '';
    }
  }).blur(function() {
    if (this.value === '' || this.value === null) {
      this.value = this.initValue;
    }
  });
})(window, jQuery);