        var barIntervalId = 0;
        var flashPlayer;
        $(document).ready(function(){
            $(document).pngFix();
            $("#ckbrbutton").click(shwchkbar);
            $("div.searchcontainer input").change(showsuggestion);
            $("div.searchcontainer input").keyup(showsuggestion);
            $("div.searchcontainer input").click( function () { 
				detectFlashPlayer();
				$("div.searchcontainer input").attr("value", "");
				$("#suggestionlist").css("visibility","hidden"); 
				switchBar(0);
				flashPlayer.hideBar();
			});

            switchBar(0);
            $("#fakelayer").hover(function(){
                  switchBar(1);                 
            }, function(){
                 
            });
            $("#content").hover(function(){
                switchBar(0);                 
                detectFlashPlayer();  
                flashPlayer.hideBar();              
            }, function(){
                   
            });           
             $("#content").click(function(){
                 switchBar(0);       
                 detectFlashPlayer();  
    			 flashPlayer.hideBar();                        
             });
             $("#footer").click(function(){
                 switchBar(1);                 
             });
        });

        function detectFlashPlayer(){
            flashPlayer =  document.getElementById('obj_cocktailbarcontainer');
        }

        function switchBar(pos){
                if(pos == 1){
                    $("#content").css("z-index", "10");
                    $("#footer").css("z-index", "20");
                    $("#fakelayer").css("z-index", "15");
                }else{
                    $("#content").css("z-index", "20");
                    $("#fakelayer").css("z-index", "25");
                    $("#footer").css("z-index", "10");
                }
        }

        function shwchkbar(){
            var hbar = $("#cocktailbar").css("height");
            if(parseInt(hbar) == 0){
                barIntervalId = setInterval("showbar()", 50);
            }else{
                barIntervalId = setInterval("hidebar()", 50);
            }
        }

        function showsuggestion(){
            if($("div.searchcontainer input").val().length > 0){
                $.post(
                    '/video/preparesearch',
                    {text:$("div.searchcontainer input").val()},
                    function(data){
                        switchBar(1);
                        $("#suggestionlist").html(data);
                        $("#suggestionlist").css("visibility","visible");
                    }
                );
            }else{
                $("#suggestionlist").css("visibility","hidden");
            }
        }

        function showbar(){
            $("#cocktailbar").css("overflow","hidden");
            $("#cocktailbar").css("display","block");
            var mrbut = $("#ckbrbutton").css('margin-top');
            var hbar = $("#cocktailbar").css("height");
            var hfoot = $("#footer").css("height");
            if(parseInt(hbar)>90){
                clearInterval(barIntervalId);
                $("#cocktailbar").css("overflow","auto");
                return true;
            }
            mrbut = parseInt(mrbut)-1;
            hbar = parseInt(hbar)+1;
            hfoot = parseInt(hfoot)+1;
            $("#ckbrbutton").css('margin-top',mrbut);
            $("#cocktailbar").css("height",hbar);
            $("#footer").css("height",hfoot);
            $("#footer").css("margin-top",-hfoot);
            mrbut = $("#ckbrbutton").css('margin-top');
            hbar = $("#cocktailbar").css("height");
            hfoot = $("#footer").css("height");
        }


        function hidebar(){
            $("#cocktailbar").css("overflow","hidden");
            var mrbut = $("#ckbrbutton").css('margin-top');
            var hbar = $("#cocktailbar").css("height");
            var hfoot = $("#footer").css("height");
            if(parseInt(hbar)<1){
                $("#cocktailbar").css("display","none");
                $("#cocktailbar").css("overflow","auto");
                clearInterval(barIntervalId);
                return true;
            }
            mrbut = parseInt(mrbut)+1;
            hbar = parseInt(hbar)-1;
            hfoot = parseInt(hfoot)-1;
            $("#ckbrbutton").css('margin-top',mrbut);
            $("#cocktailbar").css("height",hbar);
            $("#footer").css("height",hfoot);
            $("#footer").css("margin-top",-hfoot);
            mrbut = $("#ckbrbutton").css('margin-top');
            hbar = $("#cocktailbar").css("height");
            hfoot = $("#footer").css("height");
        }
