jQuery(function( $ ){
	$.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;
	};

	$('ul.updown').click(function(e){ e.preventDefault(); var link = e.target; link.blur(); if( link.title ) $(this).parent().find('span.message').text(link.title); });
	
	$('div.pane').scrollTo( 0 );
	$.scrollTo( 0 );
	
	var scrollMove = '150px';
	var scrollMoveCustom = '300px';
	var scrollNumber = 3;
	
	var $paneTarget1 = $('#index-news-pane-1');
	var $paneTarget2 = $('#index-news-pane-2');
	var $paneTarget3 = $('#index-news-pane-3');	
	
	var indexpane1 = 1; var indexpane2 = 1; var indexpane3 = 1;
	
	$('#down1').click(function(){ $paneTarget1.stop().scrollTo( {top:'+='+scrollMove,left:'0'}, 500 ); indexpane1 += 1;});
	$('#up1').click(function(){ $paneTarget1.stop().scrollTo( {top:'-='+scrollMove,left:'0'}, 500 ); indexpane1 -= 1;});
	$('#down2').click(function(){ $paneTarget2.stop().scrollTo( {top:'+='+scrollMove,left:'0'}, 500 ); indexpane2 += 1;});
	$('#up2').click(function(){ $paneTarget2.stop().scrollTo( {top:'-='+scrollMove,left:'0'}, 500 ); indexpane2 -= 1;});
	$('#down3').click(function(){ $paneTarget3.stop().scrollTo( {top:'+='+scrollMove,left:'0'}, 500 ); indexpane3 += 1;});
	$('#up3').click(function(){ $paneTarget3.stop().scrollTo( {top:'-='+scrollMove,left:'0'}, 500 ); indexpane3 -= 1;});
	
	$("#more1").click(function(){
		if(indexpane1>scrollNumber) {indexpane1=scrollNumber;} else if(indexpane1<1) {indexpane1=1;}
		window.location = "index.php?action=shownews&type=ossi&no="+indexpane1;
		//alert(indexpane1);
		// prikazi vest!
	});
	$("#more2").click(function(){
		if(indexpane2>scrollNumber) {indexpane2=scrollNumber;} else if(indexpane2<1) {indexpane2=1;}
		window.location = "index.php?action=shownews&type=dept&no="+indexpane2;
		//alert(indexpane2);
		// prikazi vest!
	});
	$("#more3").click(function(){
		if(indexpane3>scrollNumber) {indexpane3=scrollNumber;} else if(indexpane3<1) {indexpane3=1;}
		window.location = "index.php?action=shownews&type=good&no="+indexpane3;
		//alert(indexpane3);
		// prikazi vest!
	});
	
	$("#newsback").click(function(){
		window.location = "index.php";
	});
	
	$paneTargetCustom = $('#custom-pane');
	$('#down-custom').mousehold(function(){ $paneTargetCustom.stop().scrollTo( {top:'+='+scrollMoveCustom,left:'0'}, 500 );});
	$('#up-custom').mousehold(function(){ $paneTargetCustom.stop().scrollTo( {top:'-='+scrollMoveCustom,left:'0'}, 500 );});
	
	$paneTargetFirm = $('#firm-pane');
	$('#down-custom').mousehold(function(){ $paneTargetFirm.stop().scrollTo( {top:'+='+scrollMoveCustom,left:'0'}, 500 );});
	$('#up-custom').mousehold(function(){ $paneTargetFirm.stop().scrollTo( {top:'-='+scrollMoveCustom,left:'0'}, 500 );});
	
	
	var scrollMoveArchive = '100px';
	$paneTargetArchive1 = $('#archive-pane-1');
	$paneTargetArchive2 = $('#archive-pane-2');
	$paneTargetArchive3 = $('#archive-pane-3');
	$('#down-arch1').mousehold(function(){ $paneTargetArchive1.stop().scrollTo( {top:'+='+scrollMoveArchive,left:'0'}, 500 );});
	$('#up-arch1').mousehold(function(){ $paneTargetArchive1.stop().scrollTo( {top:'-='+scrollMoveArchive,left:'0'}, 500 );});
	$('#down-arch2').mousehold(function(){ $paneTargetArchive2.stop().scrollTo( {top:'+='+scrollMoveArchive,left:'0'}, 500 );});
	$('#up-arch2').mousehold(function(){ $paneTargetArchive2.stop().scrollTo( {top:'-='+scrollMoveArchive,left:'0'}, 500 );});
	$('#down-arch3').mousehold(function(){ $paneTargetArchive3.stop().scrollTo( {top:'+='+scrollMoveArchive,left:'0'}, 500 );});
	$('#up-arch3').mousehold(function(){ $paneTargetArchive3.stop().scrollTo( {top:'-='+scrollMoveArchive,left:'0'}, 500 );});
	
	
	
	// tweets
	
		$("#tweets").load("js/php/tweet.php", function() {
			h = $("#tweets").height();
			
			step=100;
			i=0;
			max=Math.floor(h/step);
			
			$('#down-tweet').click(function(){
				
				if(i<max) {
					i +=1;
					$("#tweets").animate({marginTop: '-='+step+'px'}, {"duration" : 500, "easing": "linear"});
				}
			});
				
			$('#up-tweet').click(function(){
				
				if(i>0) {
					i -= 1;
					$("#tweets").animate({marginTop: '+='+step+'px'}, {"duration" : 500, "easing": "linear"});
				}
			});
		});
	


	
	
	//video
	
	$("#vv").load("js/php/videocomponent.php", function() {
			$("#videobox").load('js/php/showvideo.php');
			$("#videoname").load('js/php/showvideoname.php');
			$("#videolinksbox").load('js/php/videolinks.php', function() {

				$("#videolinks a").each(function() {
						
					$(this).click(function() {
						$("#videobox").load('js/php/showvideo.php', {'id': $(this).attr('id')});
						$("#videoname").load('js/php/showvideoname.php', {'id': $(this).attr('id')});
					});
				});
				
				$paneTargetGallery = $("#videolinks");
				$('#down-gallery').mousehold(function(){ $paneTargetGallery.stop().scrollTo( {top:'+='+scrollMoveArchive,left:'0'}, 500 );});
				$('#up-gallery').mousehold(function(){ $paneTargetGallery.stop().scrollTo( {top:'-='+scrollMoveArchive,left:'0'}, 500 );});
			});
		});
		
	


});
