$(function(){

//    var img = $("#specialimg");
//    
//    var height = img.clientWidth;
//    alert(height);
//    img.src = "images/myImage.png";
//
//    var height = img.height;
//    var width = img.width;
//    return [width,height];

    $("a.colorbox").colorbox({
		slideshow: true,
		slideshowAuto: false,
		slideshowStart: 'spustit slideshow',
		slideshowStop: 'zastavit slideshow',
		current: '{current} z(e) {total}',
		previous: 'předchozí',
		next: 'další',
		close: 'zavřít',
		maxHeight: '100%',
		scalePhotos: true,
                arrowKey:true 
    });

    $(".pdfdiv .title").live("click", function () {
        if($('.pdfdiv div').is(":visible")){
            $('.pdfdiv div').hide();
        }else{
            $('.pdfdiv div').show();
        }
    });

    // skrývání flash zpráviček
	$("div.flash").livequery(function () {
		var el = $(this);
		setTimeout(function () {
			el.animate({"opacity": 0}, 1000);
			el.slideUp();
		}, 7000);
	});
	
	$('input.searchinput').focus();

//        $("a[href^='http://']").click(function() {
//            return!window.open(this.href,'_blank');
//        });

    $(".deleteItem").live("click", function () {
        if(confirm('Opravdu chcete položku smazat?')){
          return true;
        }else{
          return false
        }
    });
    $(".editValidProcedure").live("click", function () {
        if(confirm('Opravdu chcete schválený postup editovat?')){
          return true;
        }else{
          return false
        }
    });
    $(".sendValid").live("click", function () {
        if(confirm('Opravdu chcete postup odeslat ke schválení?')){
          return true;
        }else{
          return false
        }
    });

    $(".confirmrules").colorbox({ width:"50%", inline:true, href:"#inline_rules" });
    
    
    $('.contentdiv .procedure').click(function(event) {
        var $target = $(event.target);
        if($target.attr('class') == 'author' || $target.attr('class') == 'jsauthor'){
            return true;
        }
        
        $(location).attr('href',$(this).find('a').attr('href'));
        return false;
    });
    
    
    $('.contentdiv .procedure').mouseover(function() {
        $(this).addClass('active');
        
    });
    $('.contentdiv .procedure').mouseleave(function() {
        $(this).removeClass('active');
    });
    //
    
    
    //hometrailer
    $('#hometrailer #hometraileritems .item').mouseover(function() {

         $('#hometrailer #hometraileritems .item').removeClass('active');
         $(this).addClass('active');
         
         $('#hometrailer #hometrailerimg a').hide();
         $('#hometrailer #hometrailerimg a#hti-'+$(this).attr('rel')).show();
    });
    $('#hometrailer #hometraileritems .item').click(function() {
        $(location).attr('href',$(this).find('a.title').attr('href'));
        //alert($(this).find('a.title').attr('href'));
        return false;
    });
    //hometrailer
    
    //sign popup
//    $('#accesslink').mouseover(function() {
//         $('#signdiv').show();
//    });
    $('#signdiv').mouseleave(function() {
        $('#signdiv').hide();
    });
    
    
    
});

function addSmile(smile){
    var $textArea = $("textarea");
    $textArea.focus();
    $textArea.surroundSelectedText('*'+smile+'* ','').collapseSelection(true);
}

(function($) {
	var imgList = [];
	$.extend({
		preload: function(imgArr, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);
