/**

 * @author alexander.farkas

 * @version 1.4.1

 */



jQuery(function(){

	//jQuery("#homeTabsnew>ul").tabs("#tabPanelnew", {effect: 'ajax',onClick: function(event, tabIndex) {loadjs();}});
		//jQuery("#homeTabsnew>ul").('click',function(loadjs()));
	loadjs();
	$(".sidebarTabs").tabs("#sidebarGallery ul>li", {

		effect: 'fade',

		fadeOutSpeed: "slow",

		rotate: true

	}).slideshow({

			autoplay: true,

			clickable: false,

			interval: 6000

	});

	//jQuery('.checkbox').checkBox();
	jQuery("#topMenu li").hover(function(){jQuery(this).addClass('over').children("ul").slideDown('slow');},function(){jQuery(this).removeClass('over').children("ul").slideUp('first');});
});

jQuery("#galleryId").live('mouseover',function(){
	jQuery(this).closest("#galleryTabs").find("ul").slideDown('slow');										   
}).live('mouseout',function(){var interval = window.setInterval(function(){if(!jQuery("#galleryTabs").hasClass('over')) {jQuery("#galleryTabs").find("ul").slideUp('fast');window.clearInterval(interval);}},200);})

jQuery("#galleryTabs").live('mouseover',function(){
	jQuery(this).addClass('over');										   
}).live('mouseout',function(){jQuery(this).removeClass('over');});

jQuery("#galleryTabs li a").live('click',function(){
	jQuery("#galleryTabs ul").slideUp('fast');
/*	jQuery("#gallery").append('<div class="ajaxload" />');
	jQuery.getJSON(jQuery(this).attr('href'),function(json){
		jQuery("#gallery").html(json.htmlcontent);
		if(json.jsload){
			jQuery(function(){eval(json.jsload);});
		}
	});*/  return true;
	//return false;
});



function loadgallery(){
	jQuery('.ad-gallery').adGallery({
		loader_image: 'images/loader.gif',
		slideshow: {
			enable: true,
			autostart: true,
			speed: 5000,
			start_label: 'Start',
			stop_label: 'Stop',
			stop_on_scroll: true, 
			countdown_prefix: '(', 
			countdown_sufix: ')'
		}
	});	
}


function loadjs(){

	jQuery('.scrollbox').css('overflow','hidden');

	jQuery('.scrollbox').each(function(){

		var v = jQuery(this);

		var f = jQuery(this).children('.scrollContent');

		var difference = f.height()-v.height();

		

		if(difference>0)

		{

		   var proportion = difference / f.height();

		   var handleHeight = Math.round((1-proportion)*v.height());

		   handleHeight -= handleHeight%2; 

			

		   	if(v.closest('.prelative').find('.slider-wrap').length == 0){

		   		v.after('<\div class="slider-wrap"><\div class="slider-vertical"><\/div><\/div>');

		   	}else {

				v.closest('.prelative').find(".slider-wrap").remove();

				v.after('<\div class="slider-wrap"><\div class="slider-vertical"><\/div><\/div>');

			}

		   	var sliderwrap = v.closest('.prelative').find(".slider-wrap");

		   	sliderwrap.height(v.height());

			var slideview = v.closest('.prelative').find('.slider-vertical');

		

		   slideview.slider({

			  orientation: 'vertical',

			  range: 'max',

			  min: 0,

			  max: 100,

			  value: 100,

			  slide: function(event, ui) {

				 var topValue = -((100-ui.value)*difference/100);

				 f.css({top:topValue});

			  }

		   });

		

		   v.closest('.prelative').find(".ui-slider-handle").css({height:handleHeight,'margin-bottom':-0.5*handleHeight});

			

		   var origSliderHeight =  slideview.height();

		   var sliderHeight = origSliderHeight - handleHeight ;

		   var sliderMargin =  (origSliderHeight - sliderHeight)*0.5;

		   v.closest('.prelative').find(".ui-slider").css({height:sliderHeight,'margin-top':sliderMargin});

		

		   	v.closest('.prelative').find(".ui-slider-range").css({top:-sliderMargin});

			//f.animate({top:'-'+(jQuery(".newlistItem").position().top-130)}, 500);

			//jQuery(".newlistItem").closest('.prelative').find(".ui-slider-handle").css({bottom:'0%'});

			//f.find('.newlistItem').removeClass('newlistItem');

			//$(".scrollvideos").animate({ scrollTop: stop }, 1500);

			

		   sliderwrap.click(function(){

			  slideview.slider("value", 0);

			  f.css({top:-difference});   

		   });

		

		}//end if

		

		v.mousewheel(function(event, delta){

			var speed = 1;

			var v = jQuery(this),

				u = v.find('.scrollContent'),

				x =  v.closest('.prelative').find('.slider-vertical');

			var sliderVal = x.slider("value");//read current value of the slider

			var oldposition = u.position().top;

			sliderVal += (delta*speed);//increment the current value

		

			x.slider("value", sliderVal);//and set the new value of the slider

			

			var topValue = -((100-sliderVal)*difference/100);//calculate the content top from the slider position

			

			if (topValue>0) topValue = 0;//stop the content scrolling down too much

			if (Math.abs(topValue)>difference) topValue = (-1)*difference;//stop the content scrolling up too much

			

			u.css({top:topValue});//move the content to the new position

			if(topValue){if (topValue == oldposition || Math.abs(topValue - oldposition) < 1){}else {event.preventDefault();}}

		});

	});		

}
