function weatherOnchangeForDi(value)
{
  jQuery.ajax({
    url: "/dailyinfo/weather",
    data: 'city_code='+value,
    success: function(html){
      jQuery("#weather_indicator").hide();
      jQuery("#weather_settings").html(html);
    },
    beforeSend: function (){
      jQuery("#weather_indicator").show();
    }
  });
}
function weatherHomeOnchange(value)
{
  jQuery.ajax({
    url: "/dailyinfo/weatherForHomePage",
    data: 'city_code='+value,
    beforeSend: function (){
      jQuery("#weather_indicator").show();
    },
    success: function(html){
      jQuery("#weather_indicator").hide();
      jQuery("#weather_settings").html(html);
    }
  });
}
function weatherOnchange(value)
{
  jQuery.ajax({
    url: "/dailyinfo/weather",
    data: 'city_code='+value,
    beforeSend: function (){
      jQuery("#weather_indicator").show();
    },
    success: function(html){
      jQuery("#weather_indicator").hide();
      jQuery("#weather_settings").html(html);
    }
  });
}
function voteAnswer()
{
  jQuery.ajax({
    url: "/vote/voteAnswer",
    data: jQuery("#vote_form").serialize(),
    success: function(html){
      jQuery("#vote_container").html(html);
    }
  });
}
function voteResult()
{
  jQuery.ajax({
    url: "/vote/voteResult",
    data: jQuery("#vote_form").serialize(),
    success: function(html){
      jQuery("#vote_container").html(html);
    }
  });
}

function pagerNavigation(url, elementId)
{
  if (url.charAt(0) != '/')
  {
    url = '/' + url;
  }

  jQuery.ajax({
    url: url,
    beforeSend: function (){
      var elementOffset = $('#' + elementId).offset();
      var elementHeight = $('#' + elementId).height();
      var elementWidth  = $('#' + elementId).width();
      var indicatorHeight = $('#loading_indicator').height();
      var indicatorWidth  = $('#loading_indicator').width();

      $("#"+elementId).css({
        opacity : 0.3
      });

      $('#loading_indicator').css({
        position:'absolute',
        display: 'block',
        left: elementOffset.left + (elementWidth - indicatorWidth) / 2,
        top: elementOffset.top + (elementHeight - indicatorHeight) / 2
      });
    },
    success: function(html){
      $('#loading_indicator').hide();

      $("#"+elementId).css({
        opacity : 1
      });
      $("#"+elementId).html(html);
    }
  });
}
function submitComment()
{
  jQuery.ajax({
    url: '/comment/reply',
    type: 'POST',
    data: jQuery("#comment_form").serialize(),
    success: function(html){
      jQuery("#comment_form_container").html(html);
    }
  });
}

function showCommentForm(newsId, parentId)
{
  if (typeof(parentId) == "undefined")
  {
    parentId = 0;
  }

  jQuery('.news-dialog').dialog('close');
  jQuery('#comment_form_container').load('/comment/new?news_id='+newsId + '&parent_id=' + parentId).dialog({
    title:  'Таны сэтгэгдэл',
    autoOpen: false,
    resizable: false,
    width: 400,
    height: 320
  });
  jQuery('#comment_form_container').dialog('open');
  return false;
}

function replyCommentForm(newsId, parentId)
{
  if (typeof(parentId) == "undefined")
  {
    parentId = 0;
  }

  jQuery('.news-dialog').dialog('close');
  jQuery('#comment_form_container').load('/comment/reply?news_id='+newsId + '&parent_id=' + parentId).dialog({
    title:  'Таны сэтгэгдэл',
    autoOpen: false,
    resizable: false,
    width: 400,
    height: 320
  });
  jQuery('#comment_form_container').dialog('open');
  return false;
}


function showShare(newsId)
{
  jQuery('.news-dialog').dialog('close');
  jQuery('#share_container').load('/share/index?news_id='+newsId).dialog({
    title:  'Share',
    autoOpen: false,
    resizable: false,
    width: 200,
    height: 100
  });
  jQuery('#share_container').dialog('open');
  return false;
}


function showAdvertise(adId,adName,adCategory)
{
  jQuery('.advertise-dialog').dialog('close');
  jQuery('#advertise_show_container').load('/advertise/show?id='+adId).dialog({
    title:  adName+">"+adCategory,
    resizable: false,
    width: 500,
    autoResize : true
  });
  jQuery('.advertise-dialog').dialog('open');
  return false;
}

function showSendToFriend(newsId)
{
  jQuery('.news-dialog').dialog('close');
  jQuery('#share_sendToFriend').load('/share/sendToFriend?news_id='+newsId).dialog({
    title:  'Илгээx',
    autoOpen: false,
    resizable: false,
    width: 400,
    height: 420
  });
  jQuery('#share_sendToFriend').dialog('open');
  return false;
}

function submitSendToFriend()
{
  jQuery.ajax({
    url: '/share/sendToFriend',
    type: 'POST',
    data: jQuery("#sendToForm_form").serialize(),
    success: function(html){
      jQuery("#share_sendToFriend").html(html);

    }
  });
}


function doRate(newsId, star)
{
  jQuery('#rating_container').load('/rate/rate?news_id='+newsId + '&star=' + star);
}

jQuery(document).ready(function(){

/*added new2 version*/
        $("#most-recent-mc-container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
	jQuery('#shop-featured-product-list').jcarousel({
		scroll: 1,
		auto: 0,
		wrap: 'circular'
	});

	
	jQuery('#photoAndVideoNews').jcarousel({
		scroll: 1,
		auto: 0,
		wrap: 'circular'
	});
/*added new2 version end*/

  //ajax indicator
  $("body").prepend('<div id="loading_indicator" style="display:none;">Түр xүлээнэ үү ...<img style="margin-bottom: -3px;" src="/images/loading.gif" alt="Loading"/></div>');

  var list = jQuery('#mostPopWidget ul.tabs li');
  if (list){
    list.click(function(){
      jQuery('#mostPopWidget ul.tabs li').removeClass('selected');
      jQuery(this).addClass('selected');
      jQuery('#mostPopWidget .tabContent .inner').hide();
      jQuery('#mostPopWidget .horoscope-bottom').hide();
      jQuery( jQuery(this).find('a').attr('href') ).show();
      return false;
    });
  }

  list = jQuery('#newsTabs ul.tabs li');
  if (list){
    list.click(function(){
      jQuery('#newsTabs ul.tabs li').removeClass('selected');
      jQuery(this).addClass('selected');
      jQuery('#newsTabs .tabContent .inner').hide();
      jQuery('#newsTabs .horoscope-bottom').hide();
      jQuery( jQuery(this).find('a').attr('href') ).show();
      return false;
    });
  }
  
  list = jQuery('#news-tab ul.tabber li');
  if (list){
    list.click(function(){
      jQuery('#news-tab ul.tabber li').removeClass('selected');
      jQuery(this).addClass('selected');
      jQuery('#news-tab .tabContent .inner').hide();
      jQuery('#news-tab .horoscope-bottom').hide();
      jQuery( jQuery(this).find('a').attr('href') ).show();
	  
	  $(jQuery(this).find('a').attr('href')+"-mc-container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
	  
      return false;
    });
  }

  list = jQuery("#topNewsNav li");
  if (list){
    list.mouseover(function(){
      if(jQuery(this).attr('class') != 'selected') {
        jQuery('#topNewsNav li').removeClass('selected');
        jQuery(this).addClass('selected');
        jQuery('.topNewsDiv').hide();
        jQuery( jQuery(this).attr('news') ).show();
      }
    });
  }
});


//direction true = right, false = left
function initSlider(containerId, sliderId, leftId, rightId, total_item, per_page, statusId) {
  var totalPanel = Math.ceil(total_item / per_page);
  var containerWidth = $('#'+containerId).width();
  var leftLimit = containerWidth * (totalPanel - 1);

  if (typeof(statusId) != "undefined")
  {
    var last = 1 == totalPanel ? total_item : per_page;
    $('#' + statusId).html('1-' + last+' -аас '+ total_item);
  }

  $("#" + sliderId).data("currentlyMoving", false);
  $('#' + leftId).click(function(){
    //if not currently moving
    if (($("#" + sliderId).data("currentlyMoving") == false)) {
      $("#" + sliderId).data("currentlyMoving", true);
      var movement = parseInt($("#" + sliderId).css("left")) + containerWidth;
      if (0 < movement)
      {
        movement = ( 1 - totalPanel) * containerWidth;
      }
      var page = Math.abs(movement/containerWidth);

      $("#" + sliderId)
      .stop()
      .animate({
        "left": movement
      }, function() {
        $("#" + sliderId).data("currentlyMoving", false);
        if (typeof(statusId) != "undefined")
        {
          var last = (page + 1) == totalPanel ? total_item : (page + 1) *per_page;
          $('#' + statusId).html((page * per_page +1)+ '-' + last+' -аас '+ total_item);
        }
      });
    }
    return false;
  });

  $('#' + rightId).click(function(){
    //if not currently moving
    if (($("#" + sliderId).data("currentlyMoving") == false)) {
      $("#" + sliderId).data("currentlyMoving", true);
      var movement = parseInt($("#" + sliderId).css("left")) - containerWidth;
      if (Math.abs(movement) > leftLimit)
      {
        movement = 0;
      }
      var page = Math.abs(movement/containerWidth);
      $("#" + sliderId)
      .stop()
      .animate({
        "left": movement
      }, function() {
        $("#" + sliderId).data("currentlyMoving", false);
        if (typeof(statusId) != "undefined")
        {
          var last = (page + 1) == totalPanel ? total_item : (page + 1) *per_page;
          $('#' + statusId).html((page * per_page +1)+ '-' + last+' -аас '+ total_item);
        }
      });
    }
    return false;
  });
}








function zarnatureselne()
{
  var value = parseInt($("#ad_category_id").val());
  switch(value){
    case 2:
      $("#zarna_tureeselne").show();
      break;
    case 3:
      $("#zarna_tureeselne").show();
      break;
    case 4:
      $("#zarna_tureeselne").show();
      break;
    default:
      $("#zarna_tureeselne").hide();
      break;
  }

}


