$(function() {
    /*--------------------------------------------------------------------
     * JQuery Plugin: "EqualHeights"
     * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
     * Copyright (c) 2008 Filament Group
     * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
     * Version: 2.0, 08.01.2008
    --------------------------------------------------------------------*/
    (function($) {
        $.fn.equalHeights = function(notSel) {
            if(notSel == undefined){notSel = ''};
            $(this).each(function(){
                    var currentTallest = 0;
                    $(this).children().not(notSel).each(function(i){
                            if ($(this).height() > currentTallest) {currentTallest = $(this).height();};
                    });
                    // for ie6, set height since min-height isn't supported
                    if ($.browser.msie && $.browser.version == 6.0) {$(this).children().css({'height': currentTallest});}
                    $(this).children().not(notSel).css({'min-height': currentTallest});
            });
            return this;
        };
    })(jQuery);
    //$('div.userThumbs, div.boxesUserDetail, div.jQsameHeight').equalHeights('div.clear, div.separator');
    $('div.jQsameHeight').equalHeights('div.clear, div.separator');

    (function ($) {
    $.fn.vAlign = function() {
        return $(this).children().each(function(i){
            var ch = $(this).height();
            var ph = $(this).parent().height();
            var nh = (ph - ch) / 2;
            $(this).css('padding-top', nh);
        });
    };
    })(jQuery);
    $('.vAC').vAlign();

/*
 * my jQuery
 */
// ZMENA BORDERU
$('div#artistDetailThumbs2 div.panelsOuter').hover(function(){$(this).css('border-color','#93278F')}, function(){$(this).css('border-color','#7E7E7E')})
    /*** Input Text For Search ***/
    $('input.jQfocusBlurText').each(function(){
       $(this)
        .data('text', $(this).val())
        .focus(function(){
            if($(this).val() == $(this).data('text')){$(this).val('');}
        })
        .blur(function(){
            if($(this).val() == ''){$(this).val($(this).data('text'));}
        });
    });


$('a.dopLibNemusim1').click(function(){$(this).addClass('active');});
$('a.dopLibNemusim3').click(function(){$(this).addClass('active');});
$('a.dopLibNemusim2').click(function(){$(this).addClass('active');});
$('a.icoFlame').click(function(){$(this).addClass('active');});
$('a.icoLibi').click(function(){$(this).addClass('active');});
$('a.icoNelibi').click(function(){$(this).addClass('active');});
$('a.addToFriends').click(function(){$(this).addClass('active');});
$('a.pridejdoSkupiny').click(function(){$(this).addClass('active');});

    /* MENU */
//    $("ul.topnav ul.subnav").prev('a').append("<span></span>");
//    $("ul.topnav li").hover(
//    function(){
//        $(this).find('ul.subnav').slideDown('fast').show();
//    },
//    function(){
//        $(this).find('ul.subnav').slideUp('fast');
//    });

/*
 * Bannery na home page
 */
$(window).scroll(function(){
    var baners = $("#flyBannerLeft, #flyBannerRight");
    if($(window).scrollTop() > 173){        
        if(($(window).scrollTop() > ($("#contentWrap").height() - $("#flyBannerLeft").height() + 97))){
            if(baners.css('position') == 'fixed'){
                //baners.css({position: 'absolute', top: ($("#contentWrap").height() - $("#flyBannerLeft").height() + 97)});
            }
        }else{
           //baners.css({position: 'fixed', top: 0});
        }
    }else{
        //baners.css({position: 'absolute', top: 173});
    }
});

/*
 *  MP3PLAYER
 */
$('#mp3Player .buttMP3Pplay').click(function(){
    niftyplayer('mp3PlayerFlash').play();
    return false;
});
$('#mp3Player .buttMP3Ppause').click(function(){
    niftyplayer('mp3PlayerFlash').pause();
    return false;
});
$('#mp3Player .buttMP3Pstop').click(function(){
    niftyplayer('mp3PlayerFlash').stop();
    $('div#mp3Player').stop().animate({right: -358}, 'slow' );
    return false;
});
var prevSong;
$("a[rel^='mp3Player']").click(
      function () {
        $('div#mp3Player').stop().animate({right: 0}, 'fast' );

        if(prevSong != $(this).attr("href")){
            niftyplayer('mp3PlayerFlash').loadAndPlay($(this).attr("href"));
            prevSong = $(this).attr("href");
        }else if(niftyplayer('mp3PlayerFlash').getState() == 'playing'){
            niftyplayer('mp3PlayerFlash').pause();
        }else if(niftyplayer('mp3PlayerFlash').getState() == 'paused'){
            niftyplayer('mp3PlayerFlash').play();
        }else{
            niftyplayer('mp3PlayerFlash').loadAndPlay($(this).attr("href"));
            prevSong = $(this).attr("href");
        }
        
        return false;
      }
    );



/*
 * TABS
 */	
	/*** NEWS ***/
	/*
	$("#nav ul").tabs("#panes > div", {effect: 'fade',fadeInSpeed: 400, fadeOutSpeed: 400, rotate: true,
		onBeforeClick: function(){
			//alert($(this).find('p').html());
			//$(this).find('p span').slideUp(400);//.slideUp(400);
			//$('div#newsSlider div#panes div p span');
		},
		onClick: function(){
			//alert('test');
			//$('div#newsSlider div#panes div p span')//.css('top',116).animate({top: 216}, 800);
			
		}
	}).slideshow({autoplay: true,	interval: 6000});
	*/
	
	/*** artist thumbs ***/
	/*
	$("div#artistDetailThumbs div.nav").tabs("div#artistDetailThumbs div.panels > span", {
		effect: 'fade', rotate: true
	}).slideshow({autoplay: true,	interval: 7000});
	$("div#artistDetailThumbs2 div.nav").tabs("div#artistDetailThumbs2 div.panels > a", {
		effect: 'fade', rotate: true
	}).slideshow({autoplay: true,	interval: 7000});
	*/
/*
 * SCROLLABLE
 */
	$("div.newCD div.scrollable").myScrollable({
		size: 5,
		step: 1,
		loop: true,
		firstPos: 2
	}).circular();

	$("div.newCDbig div.scrollable").myScrollable({size: 9,	step: 1, loop: true, firstPos: 4}).circular();
	
	$("div#intGal div.scrollable")
            .scrollable({
                size: 1, step: 1, loop: true, clickable: false, keyboard: false,
                onReload: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('.intGalCSS');},
                onSeek: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('.intGalCSS');}
            })
            /*.circular()*/.navigator({indexed: true, startIndex: 1, navi2: ".navi2"});
	$("div#intGal1 div.scrollable, div#intGal2 div.scrollable, div#intGal3 div.scrollable").each(function(){
            var id = $(this).parent().attr('id');
            $(this).scrollable({
                size: 1, step: 1, loop: true, clickable: false, keyboard: false,
                onReload: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('#' + id);},
                onSeek: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('#' + id);}
            })
            /*.circular()*/.navigator({indexed: true, startIndex: 1, navi2: ".navi2"});
        })
	
	/*** Nejsledovanjsi videa ***/ /*** Casopisy ***/
	$("div#nejsledVidea div.scrollable, div#casopisy div.scrollable, div#pripravAlba div.scrollable").scrollable({
		size: 4
	}).navigator({indexed: true, startIndex: 1});
	
	/*** Interpreti slider starsi videa ***/
	$("div#interpretiSlider:not(.fullHeight) div.scrollable")
            .scrollable({
                size: 1, step: 1, loop: true, clickable: false, keyboard: false
                //onReload: function(){fixHeightAuto('#intGal');}
            })
            //.circular()
            .navigator({indexed: true, startIndex: 1, navi2: ".navi2"});

	/*** Interpreti slider fullHeight starsi videa ***/
	$("div#interpretiSlider.fullHeight div.scrollable")
            .scrollable({
                size: 1, step: 1, loop: true, clickable: false, keyboard: false,
                onReload: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('.fullHeight');},
                onSeek: function(){fixHeightAutoSetActiveClass(this);fixHeightAuto('.fullHeight');}
            })
            //.circular()
            .navigator({indexed: true, startIndex: 1, navi2: ".navi2"});


/*
 * FORM TRANSFORMATION
 */
	/*** Nice Custom Form **
	$('div#filter form').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
	$('div#filterKalendar form').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
	$('div#overlayTest form').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
	$('div#overlayOtazka form').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
	$('form.overlayTest').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
	$('div.filterDesignForm form').jqTransform({imgPath:'js/jqtransform/jqtransformplugin/filter/'});
*/    

/*
 * OVERLAY
 */
    $("a[rel]").not('a.jQshowMoreText').not('a.overlayGallery').not("a[rel^='lightGallery']").overlay({
    	expose: { 
   		color: '#000', 
   		loadSpeed: 200, 
   		opacity: 0.7}, 
        top: '25%',
        effect: 'default',
        closeOnClick: false,
        api: true,
        onBeforeLoad: function() { 
        	
    		var _id = this.getTrigger().attr("id");
    		
    		if (_id != '') {     		 
				$("#s_nick").val(_id);
				$("#nl_id_foto").val(_id);
			}		
				
        	/* 
    		var title = this.getContent().find(".title");  
            var wrap = this.getContent().find("#ajaxOverlayContent");  
            
            wrap.load(this.getTrigger().attr("href"));*/
            this.getContent().find(".title").html(this.getTrigger().attr("title"));
        }
    });//.load(); 
/* 
    // select the thumbnails and make them trigger our overlay
    if($("div#intGal.intGalFoto div.item a.thumb").html() != null){
        $("div#intGal.intGalFoto div.item a.thumb").not('div#intGal div.item.cloned a').overlay({
            target: '#overlayGallery',
            expose: {
                    color: '#000',
                    opacity: 0.7}
         }).gallery({resize: true, 
        	speed: 800, 
        	opacity: 1, 
        	autohide: false, 
        	template: "<div class='fleft'><span>${index} ze <strong>${total}</strong></span></div>"});
    }
    */
});

$(document).keyup(function(event){
    if (event.keyCode == '27') {
     $('div.overlayHlaska').fadeOut("slow");
    }
});

$(document).keyup(function(event){
    if (event.keyCode == '27') {
     $('div.overlayLogin').fadeOut("slow");
    }
});

var fixHeightAutoSetActiveClass = function(api){
    if(api !== undefined){
        api.getItems().each(function(){$(this).removeClass('active');});
        api.getVisibleItems().addClass('active');
    }
}
var fixHeightAuto = function(rootID,diff){    
    if($('div' + rootID + ' .scrollable').data('podruhe') == undefined && diff == undefined){
        setTimeout("fixHeightAuto('" + rootID + "', " + diff + ")",1000);
        $('div' + rootID + ' .scrollable').data('podruhe',true);
        return;
    }

    var activeHeight = $('div' + rootID + ' .scrollable div.item.active').attr('style','').innerHeight();

    if(diff == undefined){        
        activeHeight = activeHeight + 5;
    }else{
        activeHeight = activeHeight + diff + 5;
    }
    $('div' + rootID + ' .scrollable').animate({height: activeHeight}, "slow");
};

    var jQshow = function(show,reloadScrollbar,exactID,changeText,plusPX){
        if(reloadScrollbar == undefined){reloadScrollbar = false;}
        if(exactID == undefined){exactID = false;}
        if(changeText == undefined){changeText = true;}
        if(plusPX == undefined){plusPX = 0;}

        show = $(show);
        if(!exactID){
            var item = show.parent().prev('.jQshowItem');
        }else if(exactID){
            //var item = show.parent().next('.jQshowItem');
            var item = $(exactID);
        }else{
            //var item = $(exactID);
        }
       //alert(item.html());
        var diff = 0;
        var notCloned = false;

        

        if(item.data('hOld') == undefined){
            show.data('tOld', show.html());
            if(changeText){
                show.data('tNew', 'zpět');
            }else{
                show.data('tNew', show.html());
            }

            var hNew = plusPX;
            var itemForChildren = item;
            //if($(item.children()).hasClass('wrap')){itemForChildren = $(item.children());}
            itemForChildren.children('p, div.palcuj, div.clickToMore').not('div.wrap').each(function(i){
                if(notCloned !== false && notCloned == $(this).html()){
                    notCloned = true;
                }

                if(notCloned !== true){
                    hNew = hNew + $(this).height() + parseInt($(this).css('padding-bottom')) + parseInt($(this).css('padding-top'));
                    //alert(hNew);
                }

                if(notCloned === false){
                    notCloned = $(this).html();
                }
            });
            item.data('hOld', item.height());
            item.data('hNew', hNew);
        }
        diff = item.data('hNew') - item.data('hOld');
        if(item.height() == item.data('hOld')){
            item.animate({height: item.data('hNew')}, "slow");
            show.html(show.data('tNew'));
        }else{
            item.animate({height: item.data('hOld')}, "slow");
            show.html(show.data('tOld'));
            diff = -1 * diff;
        }

        if(reloadScrollbar){
            fixHeightAuto('#' + item.parents('.intGalCSS').attr('id'),diff);
            //fixHeightAuto('.intGalCSS',diff);
        }
        //item.slideToggle("slow");
        return false;
    };

    /*
     *  overlayTest hlasky and stopky
     */
    var overlayHlaska = function(id){
        var hlaska = $("#overlay" + id);

        if(hlaska.css('display') == 'none'){
            hlaska.css('display','block');
        }else{
            hlaska.css('display','none');
        }
        return false;
    }

 

