        var additionalFetched="N";
        var height, heightAdditional, elemTop, diffHeight;
        var interval=null;
        var isExpanded=0;
        var widthOffset=0;
        var submitted=0;
        var scheduleId="0";

        Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring (navigator.userAgent.indexOf("MSIE")+5))==6;
        Prototype.Browser.IE7 = Prototype.Browser.IE && !Prototype.Browser.IE6;

//        if ( Prototype.Browser.IE6 == true ) {
//            widthOffset=2;
//            $("amazonBodyInner").setStyle({'height': '88px'});
//        }
        Event.observe(document, 'click', respondToClick);
        
        function respondToClick(event) {  
            if ( isExpanded == 1 && event.element().descendantOf("amazonAdditional") == false) {
                hideAdditional();
            }
        }        

        function adjustIE6Height() {
            if ( Prototype.Browser.IE6 == true ) {
                $("amazonInner").setStyle({'height': '88px'});
            }
        }

        function amazon(keyword, inScheduleId) {
                scheduleId = inScheduleId;
                var url = '/amazonAdvert';
		var params = 'body=1&keyword=' + keyword;
		var ajax = new Ajax.Updater(
                    {success: 'amazon'},
                    url,
                    {method: 'get', parameters: params, onFailure: reportError, onComplete: adjustIE6Height});
        }
	
        function reportError(request) {
            $('amazon').update("Error");
        }
        
        function isSubmitted() {
            if ( $("amazon_asin") != null ) {
                return true;
            } else {
                return false;
            }
        }
        
        function showAdditional() {
            if ( isSubmitted() == true ) {
                if ( additionalFetched == "N" ) {
                    additionalFetched = "Y";
                    Element.clonePosition($("amazonAdditional"), $("amazon"), {setHeight: false, setWidth: false, offsetLeft: -1 });
                    height = Element.getHeight($("amazon"));
                    heightAdditional = Element.getHeight($("amazonAdditional"));
                    var elemTopPx = $("amazonAdditional").style.top;
                    elemTop = parseInt(elemTopPx.substr(0, elemTopPx.length-2));
                    diffHeight = heightAdditional-height;
                    if ( diffHeight < 0 ) {
                        diffHeight = 0;
                    }
                    $("amazonAdditional").setStyle({'visibility': 'visible'});
                    $("amazonAdditional").setStyle({'height': '114px'});
                    
                } 
                $("amazonAdditional").setStyle({'display': 'block'});
                if ( interval != null ) {
                    window.clearInterval(interval);
                }
                new Effect.MoveAndResizeTo( "amazonAdditional", elemTop-diffHeight-12, -1, 502-widthOffset, heightAdditional, {duration: 0.4, afterFinish: opened} );
            }
        }
       
        function hideAdditional() {
            new Effect.MoveAndResizeTo( "amazonAdditional", elemTop-1, -1, 502-widthOffset, height-12, {duration: 0.4, afterFinish: closed} );
        }

        function opened(){
            isExpanded=1;
            var asin="";
            if ( submitted == 0 ) {
                submitted=1;
                asin = $("amazon_asin").value;
                $("countClick").src="/Redirect?n=1&id="+asin+"&sid="+scheduleId+"&cid=0&csid=0&type=AC&target=click";
            }
        }

        function closed(){
            $("amazonAdditional").setStyle({'display': 'none'});
            isExpanded=0;
        }        
