var interval;
var small_step = 5;			// px scrolling onmouseover arrow
var big_step = 30;			// px scrolling onmousedown arrow
var timimg = 100;			// interval length


jQuery(document).ready(function(){
	jQuery('#header').css({backgroundImage: 'url(project_files/img/header_high.png)'});
	jQuery('#image_rotation').cycle({
	    fx:      'fade',
	    speed:    1500,
	    timeout:  5000,
	    pause:   1,
	    after:  rotateOnAfter,
	    random: 1
	});

	jQuery('#references li.ref_li').mouseover(function(){
		jQuery('#references li.ref_li').removeClass('active');
		jQuery(this).addClass('active');
		jQuery('#ref_galery').attr('src',jQuery(this).children('input').val());
		jQuery('#ref_galery').height('auto');
	});
	jQuery('#references li.ref_images_li').mouseover(function(){
		jQuery('#references li.ref_li').removeClass('active');
	});

	if(jQuery('#content')) {
		var mask_h = jQuery('#content_mask').height();
		var cont_h = jQuery('#inner_content').height();

		if(cont_h > (mask_h-25)) {
			content_scrollable();



			jQuery('#arr_down').mousedown(function(){
				interval = window.clearInterval(interval);
				interval=window.setInterval("c_slide('up',big_step);", timimg);
			});
			jQuery('#arr_down').mouseup(function(){
				interval = window.clearInterval(interval);
				interval=window.setInterval("c_slide('up',small_step);", timimg);
			});
			jQuery('#arr_down').mouseover(function(){
				interval = window.clearInterval(interval);
				interval=window.setInterval("c_slide('up',small_step);", timimg);
			});
			jQuery('#arr_down').mouseout(function(){
				interval=window.clearInterval(interval);
			});

			jQuery('#arr_up').mousedown(function(){
				interval = window.clearInterval(interval);
				interval = window.setInterval("c_slide('down',big_step);", timimg);
			});
			jQuery('#arr_up').mouseup(function(){
				interval = window.clearInterval(interval);
				interval = window.setInterval("c_slide('down',small_step);", timimg);
			});
			jQuery('#arr_up').mouseover(function(){
				interval = window.clearInterval(interval);
				interval = window.setInterval("c_slide('down',small_step);", timimg);
			});
			jQuery('#arr_up').mouseout(function(){
				interval = window.clearInterval(interval);
			});
		}
	}


	/* scroll */
	
	if (jQuery('#scrollto').val() != "") {
		jQuery('#content').scrollTo('#' + jQuery('#scrollto').val(), 1000, {offset: -25});
	}
	
	

	/*
	alert(jQuery('#content').height());
	alert(jQuery('#content_mask').height());*/
});

function c_slide(dir, stepsize){


	var mask_h = jQuery('#content_mask').height();
	var cont_h = jQuery('#inner_content').height();

	var c_top 		= parseInt(jQuery('#content').scrollTop());
	var n_top		= 0;

	if(dir == 'up')		{
		if ((Math.abs(c_top) + mask_h) < (cont_h+25)) {
			n_top = c_top + stepsize;
		} else {
			n_top = c_top;
		}
	}
	if((dir == 'down'))	{
		if (c_top >= 0) {
			n_top = c_top - stepsize;
		} else {
			n_top = 0;
		}
	}
//	jQuery('#content').css('top',n_top+'px');
//	jQuery('#content').scrollTop(n_top);
	jQuery('#content').animate({scrollTop: n_top}, timimg-10);

}

function content_scrollable() {
	jQuery('#arr_up').show();
	jQuery('#arr_down').show();

	jQuery('#hider_top').show();
	jQuery('#hider_bottom').show();
}

function rotateOnAfter() {

}
