var reinitialiseScrollPane = function()
{
  $('div.scroll,div.scrolls,div.news-mains').jScrollPane({showArrows:true,scrollbarWidth:11,dragMaxHeight:8});
}

jQuery(function($) {
//scroll
$('div.scroll,div.scrolls,div.news-mains').jScrollPane({showArrows:true,scrollbarWidth:11,dragMaxHeight:8}); //,reinitialiseOnImageLoad: true

//carousel
$(".list-ps").jCarouselLite({btnNext: ".next",btnPrev: ".prev",mouseWheel: true,visible: 6});

//png fix
$('div.content-pad,div.content-pads').ifixpng();

//slide page
$.easing.elasout = function(x, t, b, c, d) {
  var s=1.70158;var p=0;var a=c;
  if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  if (a < Math.abs(c)) { a=c; var s=p/4; }
  else var s = p/(2*Math.PI) * Math.asin (c/a);
  return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
$('div.links').click(function(e){
  e.preventDefault();
  var link = e.target;
  link.blur();
});
$.scrollTo.defaults.axis = 'xy';
$('div.pane').scrollTo( 0 );
$.scrollTo( 0 );
var $paneTarget = $('#pane-target');

//horizontal scroll links
$("div.links a,#home").click(function(){$("div.links a").removeClass('a');});
$('#home').click(function(){$("div.video").css("display","block");$paneTarget.stop().scrollTo( 'li.home', 800 );return false;});
$('#about').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.about', 800 );return false;});
$('#productions').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.productions', 800 );return false;});
$('#commercials').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.commercials', 800 );return false;});
$('#enterteinment').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.enterteinment', 800 );return false;});
$('#news,img.div6').click(function(){$("#news").addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.news', 800 );return false;});
$('#work').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.work', 800 );return false;});
$('#price').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.price', 800 );return false;});
$('#div10').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.div10', 800 );return false;});
$('#projects').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.projects', 800 );return false;});
$('#div12').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.div12', 800 );return false;});
//$("#about").click(function () {$("#menu").slideToggle('slow');});

//$('#contacts').click(function(){$(this).addClass('a');$("div.video").css("display","none");$paneTarget.stop().scrollTo( 'li.contacts', 800 );return false;});
$('#contacts').click(function(){ $(this).addClass('a'); loadPageAjax('contacts_div', '/feedback/', 'contacts'); return false; });

var loadPageAjax = function (container, url, cls)
{
  var req = new JsHttpRequest();
  req.onreadystatechange = function() {
    if (req.readyState == 4) {
      document.getElementById(container).innerHTML = req.responseText;
      $("div.video").css("display","none");
      $paneTarget.stop().scrollTo( 'li.'+cls, 800 );
      reinitialiseScrollPane();
    }
  }
  req.open('GET', url, true);
  req.send({ajax: 1});
  return false;
};

});

function opennewsHome(alias) {
  $("#news").addClass('a');$("div.video").css("display","none");$('#pane-target').stop().scrollTo( 'li.news', 800 );
  DoNewsFilter('http://kaknado.com/news/', alias);
  return false;
}

