﻿/// <reference path="jquery.js" />
/// <reference path="jquery-ui.js" />
/// <reference path="jquery.tipsy.js" />

function CalendarRegister() {
   $('#calendar a.ui-state-default').hover(
    function () { $(this).addClass('ui-state-hover'); },
    function () { $(this).removeClass('ui-state-hover'); }
  );
   $('#calendar .ui-datepicker-prev').hover(
    function () { $(this).addClass('ui-state-hover ui-datepicker-prev-hover'); },
    function () { $(this).removeClass('ui-state-hover ui-datepicker-prev-hover'); }
  );
   $('#calendar .ui-datepicker-next').hover(
    function () { $(this).addClass('ui-state-hover ui-datepicker-next-hover'); },
    function () { $(this).removeClass('ui-state-hover ui-datepicker-next-hover'); }
  );
   $('#calendar a.ui-state-default').tipsy();
}


$(function () {
   var maxH = 0;

   $('#divSupport .box').each(function () {
      if ($(this).height() > maxH) {
         maxH = $(this).height();
      }
   });

   $('#divSupport .box').height(maxH);
   $('.WriteArea p').css('textAlign', 'justify');
   $('.WriteAreaContent p').css('textAlign', 'justify');


   //   $('#divSupport a').mouseover(function () {
   //      var img = $(this).css('backgroundImage').split('.');
   //      $(this).css('backgroundImage', img[0] + '_over.' + img[1]);
   //   }).mouseout(function () {
   //      var img = $(this).css('backgroundImage').split('.');
   //      $(this).css('backgroundImage', $(this).css('backgroundImage').replace('_over', ''));
   //   });


   //CalendarRegister();
   $("#UserName").watermark('Kullanıcı Adı', { useNative: false });
   $("#Password").watermark('Şifre');

   $('input[type=button]').button();
   $('#divSearchPanel').mousemove(function () { showSearchPanel('#divSearchPanel'); }).mouseleave(function () { hideSearchPanel('#divSearchPanel'); });
   $('#divLoginPanel').mousemove(function () { showSearchPanel('#divLoginPanel'); }).mouseleave(function () { hideSearchPanel('#divLoginPanel'); });
   $('#btnSearch').click(function () { showSearchPanel('#divSearchPanel'); }).mouseover(function () { showSearchPanel('#divSearchPanel'); }).mouseleave(function () { hideSearchPanel('#divSearchPanel'); });
   $('#btnLogin').click(function () { showSearchPanel('#divLoginPanel'); }).mouseover(function () { showSearchPanel('#divLoginPanel'); }).mouseleave(function () { hideSearchPanel('#divLoginPanel'); });

   $("#radio").buttonset();
   $('.button').button();
   $('li.ui-state-default').hover(
    function () { $(this).addClass('ui-state-hover'); },
    function () { $(this).removeClass('ui-state-hover'); }
  );
   $('.navigation .menu a').each(function () {
      $('.listMenu').hide();
      $(this.href).show();
      return false;
   });

   $('#SelectCouncil').change(function () {
      var value = $(this).val();
      var name = $(this)[0].options[$(this)[0].selectedIndex].getAttribute('urlname');
      if (value > 1)
         window.location = '/Konsey/' + value + '/' + name + '.html';
      else
         window.location = '/';
   });

   $('select[selected]').each(function () {
      $(this).val(this.getAttribute('selected'));
   });

   $('input:radio[name=rdoPartial]').click(function () {
      var _contentType = $(this).attr('content-type');
      var _menuId = $(this).attr('menu-id');
      var _content = $(this).attr('content');
      //Deik.Loading(_content);
      Deik.GetPartialContent(_contentType, _menuId, _content);
      return false;
   });

   // $("#navmenu-v li").hover(
   ////  alert(1);
   ////    function () { $(this).addClass("iehover"); },
   ////    function () { $(this).removeClass("iehover"); }
   //  );

   $("#navmenu-c li").bind('click',
   function () {
      var SM = "#councilSubMenuContentV1";

      $(SM).children().remove();
      $(this).children('ul').clone().appendTo(SM);
      $(SM + ' li').append('<div></div>');

      var items = $(SM + ' li');
      //      var items = $(SM + ' li').sort(function (a, b) {
      //         return $(a).width() - $(b).width()
      //      });

      $(SM).children().remove();
      $('<div class="close" ></div>').bind('click', function () { $('.councilSubMenuContainerV1').slideUp(); }).appendTo(SM);
      $(SM).append('<h2>' + $(this).children('a').attr('title') + '</h2>');

      $(SM).append('<ul></ul>');
      $(items).appendTo(SM + ' ul');
   //   $(SM).append('<div class="footerLink" > <a href="' + $(this).children('a').attr('lnk') + '">' + $(this).children('a').attr('title') + '</a></div>');

      //      $("#councilSubMenuContentV1 ul").css("margin-top", ($("#councilSubMenuContentV1").height() - $("#councilSubMenuContentV1 ul").height()) / 2);

      //      $("#councilSubMenuContentV1 ul").css("margin-left", ($("#councilSubMenuContentV1").width() - $("#councilSubMenuContentV1 ul").width()) / 2);
      $('.councilSubMenuContainerV1').slideDown();

   });

   $('.councilToolbar ul li a[menu-id]').click(function () {
      var _menuId = $(this).attr('menu-id');
      var _councilId = $(this).attr('council-id');
      $('.councilToolbar ul li').removeClass('active');
      $(this).parent().addClass('active');
      $.ajax({
         url: '/Council/PartialContent',
         data: { councilId: _councilId, menuId: _menuId },
         success: function (result) {
            $('#contentList').html(result);
         },
         error: function (x) {
            $('#contentList').html(x.responseText);
         }
      });
      return false;
   });


   //  $('div.nextProgram marquee').marquee('pointer').mouseover(function () {
   //    $(this).trigger('stop');
   //  }).mouseout(function () {
   //    $(this).trigger('start');
   //  }).mousemove(function (event) {
   //    if ($(this).data('drag') == true) {
   //      this.scrollTop = $(this).data('scrollY') + ($(this).data('y') - event.clientY);
   //    }
   //  }).mousedown(function (event) {
   //    $(this).data('drag', true).data('y', event.clientY).data('scrollY', this.scrollTop);
   //  }).mouseup(function () {
   //    $(this).data('drag', false);
   //  });
});

var CalendarButton = {
   NextMonth: function () { $('#dateChange').val(true); $('#calendarForm').submit(); },
   LastMonth: function () { $('#dateChange').val(false); $('#calendarForm').submit(); }
}

var Deik = {
   Loading: function (content) {
      $(content).html('');
      $('<img />').attr('src', '/content/images/preloader.gif')
                       .attr('title', encodeURI('Yükleniyor...'))
                       .addClass('partialContentloader').appendTo(content);
   },
   GetPartialContent: function (type, id, content) {
      if (type == -1) {
         $.get('/Home/CouncilMap', function (result) {
            $(content).html(result);
         });
      }
      else {
         $.ajax({
            url: '/Home/PartialContent',
            data: { contentType: type, menuId: id },
            cache: false,
            success: function (result) { $(content).html(result); },
            error: function (x) { $(content).html('<p>İçerik yüklenirken hata oluştu.</p>'); }
         });
      }
   }
};
function bookmarksite(title, url) {
   if (window.sidebar) // firefox
      window.sidebar.addPanel(title, url, "");
   else if (window.opera && window.print) { // opera
      var elem = document.createElement('a');
      elem.setAttribute('href', url);
      elem.setAttribute('title', title);
      elem.setAttribute('rel', 'sidebar');
      elem.click();
   }
   else if (document.all)// ie
      window.external.AddFavorite(url, title);
}



function showCouncilItems() {
   $("#councilSubMenuContentV2").children().remove();
   $('<div class="close" ></div>').bind('click', function () { $('.councilSubMenuContainerV2').slideUp(); }).appendTo('#councilSubMenuContentV2');
   $('#councilSubMenuContentV2').append('<h2>İş Konseylerimiz</h2><div id="council"></div><div id="councilSubMenuItems"></div> ');
   $("#councilItems>ul>li").each(function () {
      var item = $('<ul></ul>');
      item.append('<li class="liHeader" ><a href="javascript:;">' + $(this).children('a').attr('title') + '</a></li>');
      item.append('<li class="items" ><ul></ul></li>');

      var councilItems = $(this).children('ul').children('li').clone().sort(function (a, b) {
         return $(a).children('a').html().length - $(b).children('a').html().length
      });

      $(item).children('.items').children('ul').append(councilItems);

      $(item).children('li').children('a').bind('click', function () {

         $('#council .liHeader a').removeClass('over');
         $(this).addClass('over');

         $("#councilSubMenuContentV2 #councilSubMenuItems").children().remove();
         $("#councilSubMenuContentV2 #councilSubMenuItems").append($(this).parent().parent().children('.items').children('ul').clone()).css('borderLeft', '1px solid #B4B4B4');
         $("#councilSubMenuContentV2 #councilSubMenuItems ul").css("margin-top", ($("#councilSubMenuContentV2 #councilSubMenuItems").height() - $("#councilSubMenuContentV2 #councilSubMenuItems ul").height()) / 2);
      });

      $("#councilSubMenuContentV2 #council").append(item);
   });
   $('.councilSubMenuContainerV2').slideDown('slow');

}

function showSearchPanel(pnl) {
   $(pnl).clearQueue();
   $(pnl).show();
}
function hideSearchPanel(pnl) {
   $(pnl).clearQueue();
   $(pnl).hide();
} 
