$(window).load(function(){
	/* round images */
	$(".imgR").each(function() {
		$(this).wrap(function(){
			return '<span class="imgR" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
		});
		$(this).css("display","none");
	});
});

$(document).ready(function(){
	$('img[align="left"]').addClass('left');
	$('img[align="right"]').addClass('right');
	
	$('a[target="_blank"]').addClass('blank');
	$('a.blank').attr('target', '_blank');

	$(".fancy").fancybox({
		'width':630,
		'height':'100%',
		'autoScale':false,
		'titlePosition':'over',
		'transitionOut':'none',
		'type':'iframe',
		'scrollBar':true
	});

	//$('button').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
	
	$(".fld input").focus(function(){ $(this).addClass('write'); if (this.value==this.title){ this.value=''; } });
	$(".fld input").blur(function(){ $(this).removeClass('write'); if (this.value!=this.title){ $(this).addClass('write'); } if (this.value==''){ this.value=this.title; $(this).removeClass('write'); } });
	
	/* social box position */
	social_position();

	/*$('.cttnt2').text($('.cttnt p:first-child').text());
	$('.cttnt p:first-child').remove();*/

	// SLIDER arrows
	if($('.lstBlck').hasClass('sldLst')){
		$('.sldLst').each(function(){
			var $this = $(this);
			var move_thumb = 0; // pocet posunov
			
			$this.wrapInner('<div class="sldLstIn" />');
			$this.wrapInner('<div class="sldLstOut" />');
			$this.append('<span class="thmbArrw icn arrwPrv"></span><span class="thmbArrw icn arrwNxt"></span>');
			
			var thumb_box_width = $this.children('.sldLstOut').children('.sldLstIn').children('.itm').width() + 17; // sirka boxu
			
			if(move_thumb<=0){
				$this.children('.arrwPrv').addClass('off');
			}
						
			$this.children('.thmbArrw').click(function(){
			
			      if($(this).hasClass('arrwNxt')){
					move_thumb++;
				} else {
					move_thumb--;
				}
				
				if(move_thumb<=0){
					$this.children('.arrwPrv').addClass('off');
				} else {
					$this.children('.arrwPrv').removeClass('off');
				}
				if(move_thumb>=($this.children('.sldLstOut').children('.sldLstIn').children('.itm').size() - 4)){
					$this.children('.arrwNxt').addClass('off');
				} else {
					$this.children('.arrwNxt').removeClass('off');
				}
				
				$this.children('.sldLstOut').children('.sldLstIn').stop(true,true).animate({marginLeft: -1 * move_thumb * thumb_box_width + "px"}, 500);
				
				return false;
			});
		});
	}
	
	// SLIDER rotate
	$(".sldrNav li:first").addClass("cur");
	$(".sldrCon div").css('opacity','0').css('zIndex','1');
	$(".sldrCon div:first").addClass("activeSlide").css('zIndex','3').css('opacity','1');
	$(".sldrCon div:first").next().addClass("nextActiveSlide").css('zIndex','2').css('opacity','0');
      $('.wlcSldr .note').text($(".sldrCon div:first").children('a').children('img').attr('alt'));

	rotate = function(){

		$(".sldrNav li").removeClass('cur');

		var indexa = $(".sldrCon div").index($active_slide);
		
		$(".sldrNav li").eq(indexa).addClass('cur');

		$(".sldrCon div").removeClass('activeSlide');
		$(".sldrCon div").css('zIndex','1');
		$active_slide.addClass('activeSlide');
		$active_slide.css('zIndex','3');
		$active_slide.animate({opacity:1}, 800, function(){
			if($(this).prev().length!=0){
				$(this).prev().css('opacity','0');
				$(this).next().css('opacity','0');
				$(".sldrCon div:first").css('opacity','0');
			}
			else {
				$(".sldrCon div:last").css('opacity','0');
				$(this).prev().css('opacity','0');
				$(this).next().css('opacity','0');
			}
		});

		$(".sldrCon div.nextActiveSlide").removeClass('nextActiveSlide');
		$next_active_slide.addClass('nextActiveSlide');
		$next_active_slide.css('zIndex','2');
		
		$('.wlcSldr .note').text($active_slide.children('a').children('span').children('img').attr('alt'));
	};

	rotateSwitch = function(){
		play = setInterval(function(){
			$active = $('.sldrNav li.cur').next('li');
			$active_slide = $('.sldrCon div.activeSlide').next();
			$next_active_slide = $('.sldrCon div.activeSlide').next().next();

			if (($active.length == 0)) {
				$active = $('.sldrNav li:first');
			}
			if ( $active_slide.length == 0) {
				$active_slide = $('.sldrCon div:first');
			}
			if ( $next_active_slide.length == 0) {
				$next_active_slide = $('.sldrCon div:first');
			}
			
			rotate();
		}, 3000);
	};

	rotateSwitch();

	//$(".slider").hover(function() {clearInterval(play);},function() {rotateSwitch();});

	$(".sldrNav li").click(function() {
		var index_opts = $(this).index();
		
		if(!$(this).hasClass('cur')) {
			clearInterval(play);
			$active = $(this);
			$active_slide = $('.sldrCon div').eq(index_opts);
			$next_active_slide = $('.sldrCon div').eq(index_opts).next();
			rotate();
			rotateSwitch();
		}
		return false;
	});
});

function social_position() {
	var $scrollingDiv = $('.sclWrp');			
	$(window).scroll(function(){			
		var wrapheight = $('body').height();
		
		if($(window).scrollTop()>80){
			
			if(wrapheight>($(window).scrollTop() + $('.sclWrp').height())) {
				$scrollingDiv
				.removeClass('sideAbsolutPos')
				.addClass('sideFixedPos');
			}
		} 
		else {
			$scrollingDiv
			.removeClass('sideFixedPos')
			.addClass('sideAbsolutPos');
		}
	});
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
