// js.js - Garcy.net <-- IkE Blaster, 20100227

$(function(){ 
    $(".window-container.hidden").css({"opacity":0,"display":"block","visibility":"hidden"});
    $("#drag-open-move-close-infobox").css({"opacity":0, "display":"none"});
    $("a.openwindow").click(function(){ 
        $("#"+$(this).attr("name")).css({"z-index":zIndex++,"visibility":"visible"});
        $("#"+$(this).attr("name")).animate({"opacity":1},400);  
    });    
    $("a.external").click(function(){ 
        window.open(this.href); 
        return false;
    });
    $("#drag-open-move-close").hover(function(){
        $("#drag-open-move-close-infobox").css({"display":"block","z-index":zIndex+1}).stop().animate({"opacity":1},500);    
    }, function(){
        $("#drag-open-move-close-infobox").stop().animate({"opacity":0},500,function(){ $(this).css("display","none"); });    
    });
    
    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
// DISABLE TEXT SELECT
/*    $('.window-container').disableTextSelect(); 
    $("textarea").click(function() {
         $('.window-container').enableTextSelect();   
    });
    $("textarea").blur(function() {
         $('.window-container').disableTextSelect();   
    });       */  
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SCROLLPANE
    $('.window-container').find(".window-text").jScrollPane({showArrows:true, scrollbarWidth: 15});
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
  
   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
// DRAGABLE / RESIZEABLE
    var drag = 0;   // 0 drag, 1 resize
     
    var start;
    var startHeight;
    $('.window-container')
        .bind('dragstart',function( event ){
            if($(event.target).is('.window-title *')) {
                drag = 0;
                return true;    
            }  
            else if($(event.target).is('.window-bottombar-right')) {
                drag = 1;
                start = event.offsetY;
                startHeight = $(this).find(".jScrollPaneContainer").height();
                return true;
            } 
            return false;
        })
        .bind('drag',function( event ){
            if(drag==0) {
                var offTop = (event.offsetY>0)?event.offsetY:0;
                var offLeft = (event.offsetX>0)?event.offsetX:0;
                $( this ).css({ top: offTop, left: offLeft });
            }
            else if(drag==1) {
                if((startHeight+(event.offsetY-start)) < 28) return;
                $( this ).find(".jScrollPaneContainer").css( "height", (startHeight+(event.offsetY-start))+"px" );
                $( this ).find(".window-text").jScrollPane({showArrows:true, scrollbarWidth: 15});
            }   
        });
/*    $('.icon')
        .bind('drag',function( event ){
                var offTop = (event.offsetY>0)?event.offsetY:0;
                var offLeft = (event.offsetX>0)?event.offsetX:0;
                $( this ).css({ top: offTop, left: offLeft });
        });  */
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    

    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Z-INDEX
    var lastElmnt;
    var zIndex=100; // co klik, to vyssi z-index...
    $(".window-container").mousedown(function() {
        if(lastElmnt==$(this).attr("id")) return;
        lastElmnt = $(this).attr("id");
        $(this).css("z-index",zIndex++);   
    });
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
    
    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MINIMIZE
    var defHeight = Array();
    $(".window-title-minimize").click(function() {    
        var winContent = $(this).parent().parent().parent().find(".window-content");
        var currId = $(this).parent().parent().parent().attr("id");
        
        winContent.stop(true,true);
        
        if(winContent.css("height")=="0px") {
            if(!defHeight[currId] && $(this).parent().parent().parent().find(".window-text").height()>50) defHeight[currId] = $(this).parent().parent().parent().find(".window-text").height()+"px";
            if(!defHeight[currId]) defHeight[currId] = "400px";
            
            winContent.animate({"height":defHeight[currId]},200, function(){
                winContent.css("height","auto");    
            });
                 
        } 
        else {
            defHeight[currId] = winContent.height();   // ulozim si aktualni vysku, pri obnove pouziju
            winContent.animate({"height":"0px"},200);     
        }    
    });      
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// HIGHSLIDE GALLERY    
    $(".galleryTrigger").click(function(){ 
        $(this).parent().find(".highslide-gallery:first .highslide:first").trigger("click");  
    });
/*    $(".static.galleryTrigger").unbind("click").click(function(){return false;}).dblclick(function(){ 
        $(this).parent().find(".highslide-gallery:first .highslide:first").trigger("click");  
    });             */
    
    $(".highslide-gallery").each(function(){ // nastaveni group/expand pro nahledy
        var group = $(this).parent().find(".galleryTrigger:first").attr("id");
        if(group=="") group = $(this).parent().find(".galleryTrigger:first").attr("src");  

        $("a",this).each(function(){
            $(this).unbind("click");
            this.onclick = function() { 
                return hs.expand(this, {slideshowGroup:group});   
            };
        }); 
    });     
    $(".highslide-flash").each(function(){ // nastaveni group/expand pro nahledy
        $(this).unbind("click");
        this.onclick = function() { 
            
            var ret = hs.htmlExpand(this, { wrapperClassName: 'no-footer no-header controls-just-close no-number', objectType: 'swf', width: 700, objectWidth: 700, objectHeight: 450, maincontentText: 'You need to upgrade your Flash player', swfOptions: { version: '7' }, allowSizeReduction: false, slideshowGroup:$(this).attr("href")  } );
            $(".highslide-controls .disabled").each(function(){
                $(this).parent().css("visibility","hidden");     
            }); 
            return ret;
        };
    }); 
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
   


/*    $('textarea').growfield();
    $('textarea').growSetMin(140); 
    
    var oldRows;
    $("textarea").keydown(function() {
        if(oldRows==($(this).val().split("\n").length)) return;
        oldRows = ($(this).val().split("\n").length);   

        var txtHeight = $(this).height();
        var panel = $( this ).parent().parent().parent().find(".window-text");

        window.setTimeout(function(){ 
            panel.jScrollPane({showArrows:true, scrollbarWidth: 15});   
        },2);
        
    }); */
 

 
});



/// HIGHSLIDE OPTIONS

hs.graphicsDir = 'js/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.dimmingOpacity = 1;
hs.outlineType = 'drop-shadow';
hs.captionEval = 'this.thumb.alt';
hs.marginBottom = 105; // make room for the thumbstrip and the controls
hs.numberPosition = 'caption';
hs.showCredits = false;

// Add the slideshow providing the controlbar and the thumbstrip
hs.addSlideshow({
    //slideshowGroup: 'group1',
    interval: 5000,
    repeat: false,
    useControls: true,
    overlayOptions: {
        className: 'text-controls-garcy',
        position: 'bottom center',
        relativeTo: 'viewport',
        offsetY: -60
    },
    thumbstrip: {
        position: 'bottom center',
        mode: 'horizontal',
        relativeTo: 'viewport'
    }
});



// EOF