    function Debug(p_strMsg) {
        $("#divDebug").html(p_strMsg + "<br>" + $("#divDebug").html());
    }

    var ShowCaseView = {
        m_strFilmStripId: "",
        //m_strUlGalleryId : "",

        m_intItemCount: 0,
		
		m_objMainDivFrame: null,

        // *--------
        // canvas
        m_objDivCanvas: null,
        m_objDivCanvasTemplate: null, // the template LI
		m_objDivDefaultedCanvas: null, // the canvas to display when there's no item in the filmstrip.

        m_bMouseOverShowcase: false, // when the mouse is hovering over the canvas & thumbnails, set the value to true to stop the auto transition.
        m_bVideoPlaying: false, 	// when the video is playing, set to true to stop the auto transition.
        // external setting
        m_strCanvasImageStyle: "none", // decide how the image is going to resized,  Styles are fit, stretch, original

        // *---------
        // control panel
        m_objPlayTransitionButton: null,
        m_strPlayButtonClass: "",
        m_strPausedButtonClass: "",
        m_objNextThumbButton: null,
        m_objPrevThumbButton: null,

        // *--------
        // filmstrip
        m_objUlSource: null, // the source UL
        m_objLITemplate: null, // the template LI

        m_objDivFilmStrip: null, // the make-up FilmStrip 
        m_objUlFilmStrip: null, // the make-up FilmStrip 

        // ** thumbnail in filmstrip **
        // property
        m_intAutoTransitionInterval: 4000,
        m_intThumbAnimationTime: 600,
        m_intThumbTransitionTime: 600,
        m_strTransitionStyle: "easeInOutBack",
        m_fpThumbUnselectedOpacity: 1,
        m_strThumbStyle: "fit",
        m_intThumbWidth: 80,
        m_intThumbHeight: 80,
        m_intLIWidth: 0,
        m_intLIHeight: 0,
        // manipulation && film strip internal calculation	
		m_strUlSourceID: "",
		m_strContentSrcUrlPrepend: "",
		m_strContentSrc1UrlPrepend: "",
		m_intUlFilmStripWidth: 0,
        m_bAutoTransition: null,
        m_intLITransitionWidth: 0,
        m_objFirstThumbnail: null, 	// stores the first thumbnails from the source.  used for the initial startup.
        m_intVisibleThumbnailCount: 0, // stores the number how many Thumbnails are visible in the filmstrip.
        m_objSelectedThumb: null, 	// the currently selected thumb image
		m_intSelectedThumbIndex: 0,
        m_objLastSelectedThumb: null,
        m_bFilmStripOutBound: false, // calculated and set internally. 	indicates whether the thumbnails are reaching out of the boundary of the filmstrip

        m_bTransitionButtonEnabled: null,
		
		// event handler / callback
		onBuiltCallback: null,	// a call back function to be raised when the showcase is built.
		onThumbClickHandler: null,		// event handler for thumb images being clicked
		onCanvasClickHandler: null,		// event handler for canvas being clicked
		onInfoLinkClickHandler: null,	// event handler for Info Link button being clicked

		
		// public
		setDefaultCanvas: function($p_objDivCanvas) {
			this.m_objDivDefaultedCanvas = $p_objDivCanvas;
		},

		// public
		setMainDivFrame: function(p_strElementId) {
            this.m_objMainDivFrame = $("#" + p_strElementId);
        },
		
        // public - must set - order 1
        setUlSource: function(p_strElementId) {
            //this.m_strUlGalleryId = p_strElementId;
			this.m_objUlSource = null;
            this.m_objUlSource = $("#" + p_strElementId).clone();
			this.m_strUlSourceID = p_strElementId;
            if (this.m_objUlSource != null)
                this.m_intItemCount = this.m_objUlSource.find("li").length;
				
			this.m_strContentSrcUrlPrepend = this.m_objUlSource.attr("content_src_url_prepend");
			this.m_strContentSrc1UrlPrepend = this.m_objUlSource.attr("content_src_1_url_prepend");
        },

        // public - must set - order 2
        setFilmStrip: function(p_strElementId) {
            if (this.m_objUlSource == null) {
                alert("Please call setUlSource first before calling setFilmStrip");
            }

            this.m_objDivFilmStrip = this.m_objMainDivFrame.find("#" + p_strElementId);
            this.m_objUlFilmStrip = this.m_objDivFilmStrip.find("ul");
			this.m_intUlFilmStripWidth = parseInt(this.m_objUlFilmStrip.css("width"));

			if ( this.m_objLITemplate == null ) {
				// if the template is not set yet.
				// auto take the first list item as the item template
				if (this.m_objUlFilmStrip.find("li").length >= 1) {
					if (this.m_objUlFilmStrip.find("li").eq(0).attr("id").length > 1) {
						this.setLiTemplate(this.m_objUlFilmStrip.find("li").eq(0).attr("id"));
					}
					else {
						this.setLiTemplate(this.m_objUlFilmStrip.find("li").eq(0).attr("id", "liTemplateAuto").attr("id"));
					}
				}
				this.clearFilmStrip();
			}
        },

        // public - optional - order 3
        setLiTemplate: function(p_strElementId) {
            this.m_objLITemplate = this.m_objMainDivFrame.find("#" + p_strElementId).removeAttr('id').clone();

            this.calculateTransition();
        },
		
		calculateTransition: function() {
			//alert("calc");
			this.m_intVisibleThumbnailCount = 0;	// reset to zero
			
			this.m_intLIWidth = parseInt(this.m_objLITemplate.css("width"));
            this.m_intLIHeight = parseInt(this.m_objLITemplate.css("height"));
            var intMarginRight = this.m_objLITemplate.css("margin-right") != "" ? this.m_objLITemplate.css("margin-right") : this.m_objLITemplate.css("marginRight"); // marginRight for Opera.
            this.m_intLITransitionWidth = this.m_intLIWidth + parseInt(intMarginRight);

			//alert(this.m_intUlFilmStripWidth + " < " + (this.m_intLITransitionWidth * this.m_intItemCount));
            if (this.m_intUlFilmStripWidth  < (this.m_intLITransitionWidth * this.m_intItemCount)) {
				//alert("OutBound true: " + this.m_intItemCount);
                this.m_bFilmStripOutBound = true;
                this.m_intVisibleThumbnailCount = parseInt((this.m_intUlFilmStripWidth  / this.m_intLIWidth));
            }
            else {
				//alert("OutBound false: " + this.m_intItemCount);
                this.m_bFilmStripOutBound = false;
			}
			//alert(this.m_bFilmStripOutBound);

            this.m_objUlFilmStrip.css("width", (this.m_intLITransitionWidth * (this.m_intItemCount + this.m_intVisibleThumbnailCount * 2)) + "px");
			//alert( this.m_intLITransitionWidth + "-" + this.m_intItemCount + "-" + this.m_intVisibleThumbnailCount);
			//alert(this.m_intVisibleThumbnailCount);
		},

        // public
        setDivCanvasAndTemplate: function(p_strElementId, p_strElementId_1) {
            this.m_objDivCanvas = this.m_objMainDivFrame.find("#" + p_strElementId);
            this.m_objDivCanvasTemplate = this.m_objMainDivFrame.find("#" + p_strElementId_1).removeAttr('id').attr("tag", "canvas").css("display", "block").remove().clone();
        },

        // public
        setNextThumbButton: function(p_strElementId) {
            this.m_objNextThumbButton = this.m_objMainDivFrame.find("#" + p_strElementId);
        },

        // public
        setPrevThumbButton: function(p_strElementId) {
            this.m_objPrevThumbButton = this.m_objMainDivFrame.find("#" + p_strElementId);
        },

        // public
        setPlayTransitionButton: function(p_strElementId, p_strPlayClass, p_strPauseClass) {
            this.m_objPlayTransitionButton = this.m_objMainDivFrame.find("#" + p_strElementId);
            this.m_strPlayButtonClass = p_strPlayClass;
            this.m_strPauseButtonClass = p_strPauseClass;
        },

        // public
        setThumbSize: function(p_intWidth, p_intHeight) {
            this.m_intThumbWidth = p_intWidth;
            this.m_intThumbHeight = p_intHeight;
        },

        // public
        setThumbUnselectedOpacity: function(p_fpOpacity) {
            this.m_fpThumbUnselectedOpacity = p_fpOpacity;
        },
		
		// public
		addItem: function(p_strContentType, p_strContentSrc, p_strContentSrc1, p_strContentSrc2, p_strLink, p_strMessage, p_strTitle, p_strDataID) {
            if (this.m_strUlSourceID == "")
				return;
                
			// "<li content_type='" + m_strContentTypes[item.Type] + "' content_src='" + strUrlSmall + strImageFile + "' content_src_1='" + strUrlLarge + strImageFile + "' link='' data_id='" + item.ItemID + "' message='' title=''></li>"
			var $objLI = $("<li>");
			$objLI.attr( {
                "content_type": p_strContentType, // content type
                "content_src": p_strContentSrc.indexOf("http:") >= 0 ? p_strContentSrc : this.m_strContentSrcUrlPrepend + p_strContentSrc,		// content source
				"content_src_1": p_strContentSrc1.indexOf("http:") >= 0 ? p_strContentSrc1 : this.m_strContentSrc1UrlPrepend + p_strContentSrc1,
				"content_src_2": p_strContentSrc2,
				"link": p_strLink,
				"message": p_strMessage,
				"title": p_strTitle,
				"data_id": p_strDataID
			});
			//alert(ShowCaseView.m_objUlSource.html());
			$("#" + this.m_strUlSourceID).prepend($objLI);
			//this.m_objUlSource.append($objLI);
			this.m_intItemCount = $("#" + this.m_strUlSourceID).find("li").length;
			//this.m_intItemCount = this.m_intItemCount + 1;
			//alert(ShowCaseView.m_objUlSource.html());
			//alert("Count: " + this.m_intItemCount);
			
			this.setUlSource(this.m_strUlSourceID);
			this.calculateTransition();
			this.build();
		},
		
		// public
		removeItem: function(p_strDataID) {
            if (this.m_strUlSourceID == "")
				return;
			$("#" + this.m_strUlSourceID).find("li[data_id='" + p_strDataID + "']").remove();
			this.m_intItemCount = $("#" + this.m_strUlSourceID).find("li").length;
			//alert($("#" + this.m_strUlSourceID).find("li").length);
			//if ( $("#" + this.m_strUlSourceID).find("li").length > 0 ) {
				this.setUlSource(this.m_strUlSourceID);
				this.calculateTransition();
				this.build();
			//}
		},

        buildFilmStripItem: function(p_liItem, p_bPrepend, p_intLiNumber) {
            //alert(this.m_objLITemplate.html());
            //alert(p_liItem.find("img").attr("src"));
            var liTemplate = this.m_objLITemplate.clone();
			var liTemplateImage = liTemplate.find("img");
			/*<li 
			content_type="image" 
			content_src='http://tw.images.beanfun.gamania.com/uploaded_images/beanfun_tw/service_showcase/20100607181704890_s.jpg' 
			content_src_1='http://tw.images.beanfun.gamania.com/uploaded_images/beanfun_tw/service_showcase/20100607181704890.gif' 
			link="http://www.google.com" 
			message="" 
			title=""
			dataid="328"></li>
			*/
            liTemplateImage.attr({
                "content_type": p_liItem.attr("content_type"), // content type
                "content_src": p_liItem.attr("content_src").indexOf("http:") >= 0 ? p_liItem.attr("content_src") : this.m_strContentSrcUrlPrepend + p_liItem.attr("content_src"),		// content source
				"content_src_1": p_liItem.attr("content_src_1").indexOf("http:") >= 0 ? p_liItem.attr("content_src_1") : this.m_strContentSrc1UrlPrepend + p_liItem.attr("content_src_1"),
				"content_src_2": p_liItem.attr("content_src_2"),
				"link": p_liItem.attr("link"),
				"message": p_liItem.attr("message"),
				"title": p_liItem.attr("title"),
				"data_id": p_liItem.attr("data_id")
            });
			
			
            // determine the type of the item, and procceed accordingly.
            if (p_liItem.attr("content_type") != null && p_liItem.attr("content_type").toLowerCase() == "youtube") {
                liTemplateImage.attr("src", getYoutubeVideoThumb(getYoutubeVideoIdByUrl(liTemplateImage.attr("content_src"))));
            }
            else {
                // if the item entry is not a youtube video, it has to be an image
                //liTemplate.find("img").replaceWith(p_liItem.find("img"));
				liTemplateImage.attr("src", liTemplateImage.attr("content_src"));
            }

            if (p_intLiNumber != null) {
                liTemplateImage.attr("num", p_intLiNumber);
            }

            // resize / adjust Thumbnails size / view in the filmstrip according to the setting m_strThumbStyle
            if (ShowCaseView.m_strThumbStyle == "fit") {
                liTemplateImage.css("width", liTemplateImage.parent().css("width"));
                liTemplateImage.css("height", liTemplateImage.parent().css("height"));
            }

            // set the img opacity
            liTemplateImage.css("opacity", ShowCaseView.m_fpThumbUnselectedOpacity);

            // set the click event for the thumb image
            liTemplateImage.click(function() {
                //  if the filmstrip is animating, skip the function to avoid click spamming on the thumbnails.
                // the flag ,m_bTransitionButtonEnabled, is set in the bindNavigation function
                if (ShowCaseView.m_bTransitionButtonEnabled == true)
                    ShowCaseView.selectThumbnailByImage($(this));
				
				// if an event handler is set by external script, call and pass the required parameters to it.
				if (ShowCaseView.onThumbClickHandler != null)	// when the thumb nail is clicked.
					ShowCaseView.onThumbClickHandler(p_liItem.attr("data_id"), p_liItem.attr("content_type"), p_liItem.attr("title"), "thumb");
            });

            // set the mouseover/mouseout event for the thumb image
            liTemplateImage.mouseover(function() {
                ShowCaseView.fadeInThumbnail($(this));
            });

            liTemplateImage.mouseout(function() {
                // the currently selected thumb can not be faded out
                if (ShowCaseView.m_objSelectedThumb != null) {
                    if (ShowCaseView.m_objSelectedThumb.get(0) != liTemplateImage.get(0))
                        ShowCaseView.fadeOutThumbnail($(this));
                }
                else
                    ShowCaseView.fadeOutThumbnail($(this));
            });

            if (p_bPrepend == true)
                ShowCaseView.m_objUlFilmStrip.prepend(liTemplate);
            else
                ShowCaseView.m_objUlFilmStrip.append(liTemplate);
        },

        // private 
        buildFilmStrip: function() {
            // now build up each li from the source UL.
            if (this.m_objUlSource == null) {
                alert("Please use setUlSource() to set the source first");
                return;
            }

            if (this.m_objUlSource.find("li").length < 1) {
                //alert("no entry in the showcase");
                return;
            }

            var objUlSourceClone = null;
            if (this.m_bFilmStripOutBound == true)
                objUlSourceClone = this.m_objUlSource.clone();

            this.m_objUlSource.find("li").each(function() {
                ShowCaseView.buildFilmStripItem($(this), false);
            });
			
			this.m_objFirstThumbnail = this.m_objUlFilmStrip.find("li").eq(0).find("img");

            // if the thumb nails are reaching out the bound, then the ShowCaseView must use "strip-transition" method.
            // in that case, create enough clones of the last few items and prepend them to the beginning of the filmstrip
            // and create enough clones of the first few items and append them to the end of the filmstrip
            if (this.m_bFilmStripOutBound == true) {
                //alert(this.m_objUlFilmStrip.find("li").eq(this.m_intItemCount - 1).clone().html());
                for (var c = 0; c < this.m_intVisibleThumbnailCount; c++) {
                    ShowCaseView.buildFilmStripItem(objUlSourceClone.find("li").eq(this.m_intItemCount - 1 - c).clone(), true); // true, for prepending
                    ShowCaseView.buildFilmStripItem(objUlSourceClone.find("li").eq(c).clone(), false);
                }
            }
            else {
                // if the thumbnails are too few to fill up all the space in the filmstrip, then center the thumbnails.
                var intLeftOffset = (parseInt(this.m_objDivFilmStrip.css("width")) - parseInt(this.m_objUlFilmStrip.css("width"))) / 2;
				//alert(parseInt(this.m_objDivFilmStrip.css("width")) + " - " + parseInt(this.m_objUlFilmStrip.css("width")));
                this.m_objUlFilmStrip.css("left", intLeftOffset + "px");
            }
			
			var intLiNum = 0;
			this.m_objUlFilmStrip.find("li").each( function() {
				$(this).find("img").attr("num", intLiNum);
				intLiNum++;
			});
			

            // stop the auto transition when the mouse is on the thumbnails
            this.m_objUlFilmStrip.mouseover(function() {
                ShowCaseView.m_bMouseOverShowcase = true;
                ShowCaseView.doAutoTransition(); // when m_bMouseOverShowcase is true, this function actually clear the timer.
            }).mouseout(function() {
                ShowCaseView.m_bMouseOverShowcase = false;
                ShowCaseView.doAutoTransition();
            });

            // now remove the Source, since the items within are moved out already.
            this.m_objUlSource.remove();
			this.m_objUlSource = null;
			objUlSourceClone = null;
        },
        // private
        transitFilmStrip: function(p_intTransit) {
            //this.transitFilmStripProcess(this.m_objUlFilmStrip.position().left, p_intTransit, p_bInstantly);
            var intIndex = ShowCaseView.getSelectedThumbIndexWithBuffered() + p_intTransit;
            this.transitFilmStripToWithBuffered(intIndex, false);
        },

        // private
        // p_intRealIndex is the real index of the thumb of the original source; excluding the buffer thumbs.
        transitFilmStripTo: function(p_intRealIndex, p_bInstantly) {
            var intIndex = this.m_intVisibleThumbnailCount + p_intRealIndex;

            this.transitFilmStripProcess(0, intIndex, p_bInstantly);
        },

        // private
        // p_intIndex is the index of the thumbs including the buffer thumbs.
        transitFilmStripToWithBuffered: function(p_intIndex, p_bInstantly) {
            var intIndex = p_intIndex;

            this.transitFilmStripProcess(0, intIndex, p_bInstantly);
        },

        transitFilmStripProcess: function(p_intBaseLeft, p_intTransit, p_bInstantly) {
			//alert(p_intTransit);
            ShowCaseView.doAutoTransition(); // reset the auto transition timer to avoid unexpected transiting.

            if (this.m_bFilmStripOutBound == true) {
                this.bindNavigationButton(false);

                var intLeft = p_intBaseLeft + (this.m_intLITransitionWidth * p_intTransit * -1);
                if (p_bInstantly == true) {
                    this.m_objUlFilmStrip.css("left", intLeft);
                    ShowCaseView.bindNavigationButton(true); // set back the click binding
                    ShowCaseView.doAutoTransition();

                    //var intBufferedIndex = ShowCaseView.getSelectedThumbIndexWithBuffered();
                }
                else {
                    this.m_objUlFilmStrip.stop().animate({
                        'left': intLeft + "px"
                    }, this.m_intThumbTransitionTime, this.m_strTransitionStyle, function() {
                        // callback function on animation completed
                        var intBufferedIndex = ShowCaseView.getSelectedThumbIndexWithBuffered();

                        if (intBufferedIndex >= (ShowCaseView.m_intItemCount + 1)) {
							var intJunmpIndex = intBufferedIndex % ShowCaseView.m_intItemCount;
							ShowCaseView.m_intSelectedThumbIndex = intJunmpIndex;
                            ShowCaseView.transitFilmStripToWithBuffered(intJunmpIndex, true);
							
                        } else if (intBufferedIndex <= 0) {
							ShowCaseView.m_intSelectedThumbIndex = ShowCaseView.m_intItemCount;
                            ShowCaseView.transitFilmStripToWithBuffered(ShowCaseView.m_intItemCount, true);
							//ShowCaseView.m_intSelectedThumbIndex = ShowCaseView.m_intItemCount;
                        }
                        ShowCaseView.selectNextThumbnail(0, true);
                        ShowCaseView.createNextCanvasBuffer();


                        ShowCaseView.bindNavigationButton(true); // set back the click binding
                    });
                }
            }
        },

        getSelectedThumbIndexWithBuffered: function() {
            var intLeft = parseInt(this.m_objUlFilmStrip.css("left"));
			
			//Debug(Math.abs(parseInt(intLeft / this.m_intLITransitionWidth)) + " - " + this.m_intSelectedThumbIndex);
            //return Math.abs(parseInt(intLeft / this.m_intLITransitionWidth));
			return parseInt(this.m_intSelectedThumbIndex);
        },

        bindNavigationButton: function(p_bBind) {
            if (this.m_bTransitionButtonEnabled == p_bBind)
                return;
            this.m_bTransitionButtonEnabled = p_bBind; // the flag on the thumbnail clicking event.

            if (p_bBind == true) {
                // set the next button click event
                if (ShowCaseView.m_objNextThumbButton != null) {
                    ShowCaseView.m_objNextThumbButton.unbind("click");
                    ShowCaseView.m_objNextThumbButton.click(function() {
                        ShowCaseView.selectNextThumbnail(1);
                    });
                }

                // set the prev button click event
                if (ShowCaseView.m_objPrevThumbButton != null) {
                    ShowCaseView.m_objPrevThumbButton.unbind("click");
                    ShowCaseView.m_objPrevThumbButton.click(function() {
                        ShowCaseView.selectNextThumbnail(-1);
                    });
                }

                if (ShowCaseView.m_objPlayTransitionButton != null) {
                    ShowCaseView.m_objPlayTransitionButton.unbind("click");
                    ShowCaseView.m_objPlayTransitionButton.click(function(e) {
                        ShowCaseView.switchAutoTransition(!ShowCaseView.isOnAutoTransition());
                        //alert(ShowCaseView.isOnAutoTransition());
                        if (ShowCaseView.isOnAutoTransition() == true) {
                            ShowCaseView.m_objPlayTransitionButton.removeClass(ShowCaseView.m_strPlayButtonClass);
                            ShowCaseView.m_objPlayTransitionButton.addClass(ShowCaseView.m_strPauseButtonClass);
                        }
                        else {
                            ShowCaseView.m_objPlayTransitionButton.removeClass(ShowCaseView.m_strPauseButtonClass);
                            ShowCaseView.m_objPlayTransitionButton.addClass(ShowCaseView.m_strPlayButtonClass);
                        }

                    });
                }
            }
            else {
                // unbind all the button
                if (ShowCaseView.m_objNextThumbButton != null) {
                    ShowCaseView.m_objNextThumbButton.unbind("click");
                }

                if (ShowCaseView.m_objPrevThumbButton != null) {
                    ShowCaseView.m_objPrevThumbButton.unbind("click");
                }

                /*if ( ShowCaseView.m_objPlayTransitionButton != null ) {
                ShowCaseView.m_objPlayTransitionButton.unbind("click");
                }*/
            }
        },

        // private
        buildControlPanel: function() {
            this.bindNavigationButton(true);
        },

        // public
        build: function() {
			this.m_objMainDivFrame.find(".loader").fadeOut(1500, function() {
				var $objTemp = $(this).remove();
				$objTemp = null;
			});

            this.clearFilmStrip();
            this.buildFilmStrip();
            this.buildControlPanel();

            //this.transitFilmStripTo(0, true);
			if ( this.m_objFirstThumbnail == null ) { 
				// if the startup thumbnail is not set, something must be wrong.
				// probably there's no item in the filmstrip.  Zero source~!
				if (this.m_objDivDefaultedCanvas != null ) {
					this.m_objDivCanvas.append( this.m_objDivDefaultedCanvas );
				}
				return;
			}
			
            this.selectThumbnailByImage(this.m_objFirstThumbnail);
			this.m_intSelectedThumbIndex = this.m_objFirstThumbnail.attr("num");
			this.m_objFirstThumbnail = null;

            // start the auto transition
            this.switchAutoTransition(true);
			//this.switchAutoTransition(false);
			
			if( this.onBuiltCallback != null )
				this.onBuiltCallback();
        },

        // private
        doAutoTransition: function() {
            // start the auto transition
            //if (typeof ($(document).oneTime) == "function") {
                $(document).stopTime("ShowcaseAutoTransition");
                if (this.isOnAutoTransition() == true && this.m_bMouseOverShowcase == false && this.m_bVideoPlaying == false) {
                    $(document).oneTime(ShowCaseView.m_intAutoTransitionInterval, "ShowcaseAutoTransition", function() {
                        ShowCaseView.selectNextThumbnail(1);
                    });
                }
            //}
        },

        // private
        switchAutoTransition: function(p_bAuto) {
            if (this.m_bAutoTransition == p_bAuto)
                return;

            this.m_bAutoTransition = p_bAuto;

            // start the auto transition
            this.doAutoTransition();
        },

        // private
        isOnAutoTransition: function() {
            return this.m_bAutoTransition;
        },

        // private function
        fadeInThumbnail: function(p_objImage, p_bInstant) {
            if (p_bInstant == true)
                p_objImage.css("opacity", "1");
            else
                p_objImage.stop().animate({ 'opacity': '1' }, this.m_intThumbAnimationTime);
        },

        // private function
        fadeOutThumbnail: function(p_objImage, p_bInstant) {
            if (p_bInstant == true)
                p_objImage.css("opacity", this.m_fpThumbUnselectedOpacity);
            else
                p_objImage.stop().animate({ 'opacity': this.m_fpThumbUnselectedOpacity }, this.m_intThumbAnimationTime);
        },

        // public function
        selectNextThumbnail: function(p_intIndex, p_bInstant) {
            var intIndex = 0;
            if (this.m_bFilmStripOutBound == true) {
                intIndex = ShowCaseView.getSelectedThumbIndexWithBuffered() + p_intIndex;
            }
            else {
                // if no thumbnail is selected, then select the first thumbnail; else select the proper one.
                intIndex = this.m_objUlFilmStrip.find('li').index(this.m_objUlFilmStrip.find("li.current")) == -1 ? 0 : this.m_objUlFilmStrip.find('li').index(this.m_objUlFilmStrip.find("li.current"));
                //alert(intIndex);
				intIndex = intIndex + p_intIndex;
				//alert(intIndex);
                if (intIndex == this.m_intItemCount)
                    intIndex = 0; // the index is reaching to the last thumbnail, jump back to the first thumb.
				else if (intIndex < 0 ) 
					intIndex = this.m_intItemCount - 1;
            }
			//alert("=" + intIndex);
            this.selectThumbnailByImage(this.m_objUlFilmStrip.find("li").eq(intIndex).find("img"), p_bInstant);
        },

        // public function
        selectThumbnailByImage: function(p_objThumb, p_bInstant) {
			if ( p_objThumb == null ) return;
			
			this.m_intSelectedThumbIndex = p_objThumb.attr("num");
			//alert(p_objThumb.attr("num"));
			
            // if the filmstrip transition requires moving filmstrip,
            // then move the filmstrip when the thumb is clicked/selected
            if (this.m_bFilmStripOutBound == true) {
                //var intIndex = $('li').index(p_objThumb.closest("li"));
				//var intIndex = p_objThumb.closest("li").index();
				//alert("index: " + intIndex);
                this.transitFilmStripToWithBuffered(this.m_intSelectedThumbIndex, p_bInstant);
            }
			else
				ShowCaseView.doAutoTransition();

            if (this.m_objSelectedThumb != null) {
                if (this.m_objSelectedThumb.get(0) == p_objThumb.get(0))
                    return;
                else {
                    var objLI = this.m_objUlFilmStrip.find("li.current");
                    // clear the associated LI state
                    objLI.removeClass("current");
                    // clear the previously selected thumbnail state
                    this.fadeOutThumbnail(objLI.find("img"));
                }
            }

            // set the image to the selected state
            this.fadeInThumbnail(p_objThumb, p_bInstant);
            // set the accociated LI state
            p_objThumb.closest("li").addClass("current");

            // set the pointer to the newly selected thumb
            this.m_objSelectedThumb = p_objThumb;
			
            if (p_bInstant != true)	//  p_bInstant is true only when the thumbnail transition reachs the loop point.
            {
                if (this.m_objDivCanvas.find("div[num='" + this.m_intSelectedThumbIndex + "']").length >= 1) {
                    this.displayBufferToCanvas(this.m_intSelectedThumbIndex);
					//Debug("selectThumbnailByImage: displayBufferToCanvas()");
                }
                else {
                    this.displayToCanvas(p_objThumb.closest("li")); // when the transition reachs the loop point, do not call displayToCanvas for it will refresh the canvas; fadeIn & fadeOut
					//Debug("selectThumbnailByImage: displayToCanvas()");
                }

            }
        },

        setCanvasImageStyle: function(p_strStyle) {
            this.m_strCanvasImageStyle = p_strStyle.toLowerCase();
        },

        createNextCanvasBuffer: function() {
            var intIndex = 0;
            if (this.m_bFilmStripOutBound == true) {
                intIndex = ShowCaseView.getSelectedThumbIndexWithBuffered() + 1;
            }
            else {
                // if no thumbnail is selected, then select the first thumbnail; else select the proper one.
                intIndex = $('li').index(this.m_objUlFilmStrip.find("li.current")) == -1 ? 0 : $('li').index(this.m_objUlFilmStrip.find("li.current"));
                intIndex = intIndex + 1;
                if (intIndex == this.m_intItemCount)
                    intIndex = 0; // the index is reaching to the last thumbnail, jump back to the first thumb.
            }
			
			//var intNum = this.m_objUlFilmStrip.find("li").eq(intIndex).find("img").attr("num");
			if (this.m_objDivCanvas.find("div[num='" + intIndex + "']").length >= 1) {
				// buffer already created
				//Debug("buffer already created");
			}
			else {
				//Debug("buffer none");
				this.createCanvasBuffer(this.m_objUlFilmStrip.find("li").eq(intIndex));
			}
        },
		
		my_test: function() {
			window.open("http://www.google.com");
		},

        createCanvasBuffer: function(p_objLI) {
            // if the Canvas is not register
            if (this.m_objDivCanvas == null || this.m_objDivCanvasTemplate == null)
                return;

			var objThumb = p_objLI.find("img");
			
            var objCanvasTemplate = this.m_objDivCanvasTemplate.clone();
            objCanvasTemplate.attr("num", objThumb.attr("num"));

            // stop the auto transition when the mouse is on the canvas
            objCanvasTemplate.mouseover(function() {
                ShowCaseView.m_bMouseOverShowcase = true;
                ShowCaseView.doAutoTransition(); // when m_bMouseOverShowcase is true, this function actually clear the timer.
            }).mouseout(function() {
                ShowCaseView.m_bMouseOverShowcase = false;
                ShowCaseView.doAutoTransition(); // when m_bMouseOverShowcase is true, this function actually clear the timer.
            });
			
			var objCanvasTemplateImage = objCanvasTemplate.find("img");
			/*objCanvasTemplateImage.attr({
				"data_id": objThumb.attr("data_id"),
				"content_type": objThumb.attr("content_type"),
				"title": objThumb.attr("title"),
				"link": objThumb.attr("link")
			});*/
			// set the link if there's one
			//if ( objThumb.attr("link").length > 5 ) {
			objCanvasTemplateImage.bind("click", { strDataID:objThumb.attr("data_id"), strContentType:objThumb.attr("content_type"), strTitle:objThumb.attr("title"), strLink:objThumb.attr("link")}, function(event) {
				if ( event.data.strLink != null && event.data.strLink.length > 5 && event.data.strContentType == "image" ) {	// if this canvas is a video/youtube type, then do not do Window.open here, since clicking the canvas is meant to start up the video but not opening window.
					//setTimeout('window.open("' + event.data.strLink + '")', 200);	// must use the timer to delay the window.open, else the ajax(webtrend) and window open will mess up
					window.open( event.data.strLink);	// since Chrome does not allow javascript calling a window.open during loading (window.onload or setTimeout event). So, make the window.open an instant call, and delay the external handler.
				}
				// if an event handler is set by external script, call and pass the required parameters to it.
				if (ShowCaseView.onCanvasClickHandler != null) {
					//ShowCaseView.onCanvasClickHandler(event.data.strDataID, event.data.strContentType, event.data.strTitle, "canvas");
					setTimeout('ShowCaseView.onCanvasClickHandler("' + event.data.strDataID + '", "' + event.data.strContentType + '", "' + event.data.strTitle + '", "' + "canvas"+ '")', 800);
				}
			});
			
			objCanvasTemplate.find("#divInfoLink").bind("click", { strDataID:objThumb.attr("data_id"), strContentType:objThumb.attr("content_type"), strTitle:objThumb.attr("title"), strLink:objThumb.attr("link")}, function(event) {
				if ( event.data.strLink != null && event.data.strLink.length > 5 ) {
					//setTimeout('window.open("' + event.data.strLink + '")', 200);	// must use the timer to delay the window.open, else the ajax(webtrend) and window open will mess up
					window.open( event.data.strLink);	// since Chrome does not allow javascript calling a window.open during loading (window.onload or setTimeout event). So, make the window.open an instant call, and delay the external handler.
				}
				// if an event handler is set by external script, call and pass the required parameters to it.
				if (ShowCaseView.onInfoLinkClickHandler != null) {
					//ShowCaseView.onInfoLinkClickHandler(event.data.strDataID, event.data.strContentType, event.data.strTitle, "button");
					setTimeout('ShowCaseView.onCanvasClickHandler("' + event.data.strDataID + '", "' + event.data.strContentType + '", "' + event.data.strTitle + '", "' + "canvas"+ '")', 800);
				}
			});

			
			// display the message if there's any.£» divMessageWrapper
			var objCanvasTemplateMessageWrapper = objCanvasTemplate.find("#divMessageWrapper");
			//objCanvasTemplateMessageWrapper.find("#divBackground").css("opacity", 0.7);

			if ( objThumb.attr("message") != null && objThumb.attr("message").length > 1 ) {
				objCanvasTemplateMessageWrapper.css("display", "block");
				objCanvasTemplateMessageWrapper.find("#spanMessage").html( objThumb.attr("message") );
			}
			else
				objCanvasTemplateMessageWrapper.remove();

			var strContentType = objThumb.attr("content_type") != null ? objThumb.attr("content_type").toLowerCase() : "";
			objCanvasTemplate.attr("content_type", strContentType);
            // now check the content type of the list item, and procceed accordingly.
            if ( objCanvasTemplate.attr("content_type") == "youtube") {
				var strVideoID = getYoutubeVideoIdByUrl(objThumb.attr("content_src")); // parse the video id from the video page url
				
				objCanvasTemplateImage.attr("src", getYoutubeVideoThumb(objThumb.attr("content_src")));
				this.m_objDivCanvas.prepend(objCanvasTemplate);
				
				var divOverlayPlay = $("<div id='divOverlayPlay' class='overlayPlay'>");
				divOverlayPlay.attr("data_id", objThumb.attr("data_id"));
				divOverlayPlay.css("opacity", 0.7);
				var divWrapper = objCanvasTemplateImage.parent(); // insert the video object into this wrapper
				divWrapper.prepend(divOverlayPlay);

				divOverlayPlay.click( function() {
					objCanvasTemplateImage.click();
					
					$(this).css("display", "none");
					objCanvasTemplateImage.css("display", "none"); // remove any images
					
					var divPlayer = $("<div id='divTYPlayer'></div>")
					divWrapper.append(divPlayer);

					//var objImgAttrs = ShowCaseView.getCanvasFitSize(objCanvasTemplate.width(), objCanvasTemplate.height());
					var objImgAttrs = {width:objCanvasTemplate.width(), height:objCanvasTemplate.height(), top:0, left:0 };	// forcefully set to fit the canvas size
					if (objImgAttrs.top != null) {
						divWrapper.css({
							"position": "relative",
							"left": objImgAttrs.left + "px",
							"top": objImgAttrs.top + "px"
						});
					}

					// The video to load
					var strContainer = divPlayer.attr("id");
					// Lets Flash from another domain call JavaScript
					var params = { allowScriptAccess: "always", wmode: "opaque" };
					// The element id of the Flash embed
					var atts = { id: "ShowCaseYTPlayer" };
					// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
					swfobject.embedSWF("http://www.youtube.com/v/" + strVideoID +
								 "&enablejsapi=1&autoplay=1&playerapiid=player1",
								 strContainer, objImgAttrs.width, objImgAttrs.height, "8", null, null, params, atts);
				
					objCanvasTemplateMessageWrapper.css("display", "none");
				});
							 
				
            }
			else if ( objCanvasTemplate.attr("content_type") == "video") {
                objCanvasTemplateImage.attr("src", objThumb.attr("content_src_1"));
                this.m_objDivCanvas.prepend(objCanvasTemplate);
				
				var divOverlayPlay = $("<div id='divOverlayPlay' class='overlayPlay'>");
				divOverlayPlay.attr("data_id", objThumb.attr("data_id"));
				divOverlayPlay.css("opacity", 0.7);
				var divWrapper = objCanvasTemplateImage.parent(); // insert the video object into this wrapper
				divWrapper.prepend(divOverlayPlay);

				strCurrentPlayerId = "flowplayer_" + objThumb.attr("data_id");
				var strVideoURL = objThumb.attr("content_src_2");
				
				var strWidth = objCanvasTemplate.css("width");
				var strHeight = objCanvasTemplate.css("height");
				divOverlayPlay.click( function() {
					objCanvasTemplateImage.click();
					
					$(this).css("display", "none");
					objCanvasTemplateImage.css("display", "none"); // remove any images
					
					var divPlayer = $("<a id='" + strCurrentPlayerId + "'></a>")
					//divPlayer.attr("id", strCurrentPlayerId);
					divPlayer.css({"display": "block", "height": strHeight, "width": strWidth, "position": "relative", "top": "0px", "left": "0px"});
					divWrapper.append(divPlayer);

					/*var objImgAttrs = ShowCaseView.getCanvasFitSize(480, 380);
					if (objImgAttrs.top != null) {
						divWrapper.css({
							"position": "relative",
							"left": objImgAttrs.left + "px",
							"top": objImgAttrs.top + "px"
						});
					}*/
					
					// if it's a video, call flowplayer to handle it.
					flowplayer( strCurrentPlayerId,
						"/embeds/flowplayer/flowplayer.commercial-3.1.5.swf", {
						key: GetFlowPlayerLicense(),	// GetFlowPlayerLicense() function is defined at the bottom of this file
						// change the default controlbar to tube 
						plugins: { 
							controls: { 
								url: '/embeds/flowplayer/flowplayer.controls-tube-3.1.5.swf' 
							}  
						},
						// here is our playlist with two clips
						playlist: [
							{
								url: strVideoURL,
								scaling: 'orig',
								autoPlay: true, 
								
								// video will be buffered when splash screen is visible
								autoBuffering: false
							}
						],
						onBegin  : function(){ 
							ShowCaseView.m_bVideoPlaying = true;
							ShowCaseView.doAutoTransition();
						},
						onFinish : function(){ 
							ShowCaseView.m_bVideoPlaying = false;
							ShowCaseView.doAutoTransition();
						} 
					});
					objCanvasTemplateMessageWrapper.css("display", "none");
				});
			}
            else {
                // if it's an image type item
                objCanvasTemplateImage.attr("src", objThumb.attr("content_src_1"));
                this.m_objDivCanvas.prepend(objCanvasTemplate);
				/*
					var imgCanvas = new Image();
					$(imgCanvas).load(function() {
						// now resize / change the image according to the style setup
						if (ShowCaseView.m_objDivCanvas.find("div").length != 0) {

								var objImgAttrs = ShowCaseView.getCanvasFitSize(imgCanvas.width, imgCanvas.height);
								objCanvasTemplate.find("img").css( { 
								"cursor": "pointer",
								"width" : objImgAttrs.width + "px",
								"height": objImgAttrs.height + "px"
								});
							
							if ( objImgAttrs.top != null ) {
								objCanvasTemplate.find("img").css( { 
								"left": objImgAttrs.left + "px",
								"top" : objImgAttrs.top + "px"
								});
								}

						}
						delete imgCanvas;
						imgCanvas = null;
					}).attr("src", objThumb.attr("content_src_1"));
				*/
            }
			
			objCanvasTemplateImage.attr("data_id", objThumb.attr("data_id"));
			objCanvasTemplateImage.load(function() {
				// now resize / change the image according to the style setup
				//if ( $(this).attr("resized") != 1 ) {	//if (ShowCaseView.m_objDivCanvas.find("div").length != 0) {
					//alert(objCanvasTemplateImage.attr("src") + "\nW: " + objCanvasTemplateImage.width() + " - H: " + objCanvasTemplateImage.height());
					//alert("createCanvasBuffer.resizing: " + $(this).attr("data_id") + "\n" +
					//"W: " + $(this).width() + " - H: " + $(this).height());
				var objImgAttrs = ShowCaseView.getCanvasFitSize($(this).width(), $(this).height());
				if ( objImgAttrs.width > 0 && objImgAttrs.height > 0 ) {
					$(this).css( { 
					"cursor": "pointer",
					"width" : objImgAttrs.width + "px",
					"height": objImgAttrs.height + "px"
					});

					if ( objImgAttrs.top != null ) {
						$(this).css( { 
						"left": objImgAttrs.left + "px",
						"top" : objImgAttrs.top + "px"
						});
					}
				}
					//$(this).attr("resized", 1);
				//}
				objImgAttrs = null;
			});
			
			objCanvasTemplate.css("visibility", "hidden");
			objThumb = null;
            return objCanvasTemplate;
        },

        displayToCanvas: function(p_objLI) {
			this.displayToCanvasProccess(this.createCanvasBuffer(p_objLI));
        },

        // p_intBufferNum is the number id to the buffer div.
        displayBufferToCanvas: function(p_intBufferNum) {
			this.displayToCanvasProccess(this.m_objDivCanvas.find("div[num='" + p_intBufferNum + "']"));
        },
		
		// private
		displayToCanvasProccess: function($p_objCanvasTemplate) {
			var objCanvasTemplate = $p_objCanvasTemplate;
			
            // extra code begins
            // most browsers do not require this code snippet, however, Opera needs this code to resize the image properly.  sigh extra code.
			if ( objCanvasTemplate.css("visibility") == "hidden" ) {
				var objImg = objCanvasTemplate.find("img");
				//if ( objImg.attr("resized") != 1 ) {
					//alert("displayToCanvasProccess.resizing: " + objImg.attr("data_id") + "\n" +
					//"W: " + objImg.width() + " - H: " + objImg.height());
					var objImgAttrs = ShowCaseView.getCanvasFitSize(objImg.width(), objImg.height());
					if ( objImgAttrs.width > 0 && objImgAttrs.height > 0 ) {
						objImg.css({
							"cursor": "pointer",
							"width": objImgAttrs.width + "px",
							"height": objImgAttrs.height + "px"
						});
					
						if (objImgAttrs.top != null) {
							objImg.css({
								"left": objImgAttrs.left + "px",
								"top": objImgAttrs.top + "px"
							});
						}
					}
					//objImg.attr("resized", 1);
					objImgAttrs = null;
				//}
				
				objImg.load(function() {
					// now resize / change the image according to the style setup
					//if ( $(this).attr("resized") != 1 ) {	//if (ShowCaseView.m_objDivCanvas.find("div").length != 0) {
						//alert(objCanvasTemplateImage.attr("src") + "\nW: " + objCanvasTemplateImage.width() + " - H: " + objCanvasTemplateImage.height());
						//alert("displayToCanvasProccess.resizing: " + $(this).attr("data_id") + "\n" +
						//"W: " + $(this).width() + " - H: " + $(this).height());
						var objImgAttrs = ShowCaseView.getCanvasFitSize($(this).width(), $(this).height());
						$(this).css( { 
						"cursor": "pointer",
						"width" : objImgAttrs.width + "px",
						"height": objImgAttrs.height + "px"
						});

						if ( objImgAttrs.top != null ) {
							$(this).css( { 
							"left": objImgAttrs.left + "px",
							"top" : objImgAttrs.top + "px"
							});
						}
						//$(this).attr("resized", 1);
					//}
					objImgAttrs = null;
				});
				
				objImg = null;
				objCanvasTemplate.css("visibility", "visible");
			}
            // extra code ends
			
			// fade out the previous Canvas
			var $objPreviousCanvas = this.m_objMainDivFrame.find("#divCanvasSelected");
			$objPreviousCanvas.attr("id", "").fadeOut(this.m_intThumbTransitionTime / 3);

			if ( $objPreviousCanvas.attr("content_type") == "youtube" ) {
				this.m_bVideoPlaying = false;
				swfobject.removeSWF("ShowCaseYTPlayer");	// remove Youtube player safely.
				
				$objPreviousCanvas.find("#divOverlayPlay").css("display", "block");
				$objPreviousCanvas.find("img").css("display", "block");
				$objPreviousCanvas.find("img").parent().css({
					"position": "",
					"left": "",
					"top": ""
				});
				
				$objPreviousCanvas.find("#divMessageWrapper").css("display", "block");
			}
			else if ( $objPreviousCanvas.attr("content_type") == "video" ) {
				this.m_bVideoPlaying = false;
				$objPreviousCanvas.find("a").remove();	// remove FlowPlayer; it's embedded in a <a> tab
				
				$objPreviousCanvas.find("#divOverlayPlay").css("display", "block");
				$objPreviousCanvas.find("img").css("display", "block");
				$objPreviousCanvas.find("img").parent().css({
					"position": "",
					"left": "",
					"top": ""
				});
			}
			$objPreviousCanvas = null;
			
            // find the buffered canvas and display it
			objCanvasTemplate.find("#divMessageWrapper").hide();		// fix for lousy IE's transparency bug when fading in.
			objCanvasTemplate.find("#divBackground").css("opacity", 0);	// fix for lousy IE's transparency bug when fading in.
            objCanvasTemplate.attr("id", "divCanvasSelected").fadeIn(this.m_intThumbTransitionTime, function() {
				$(this).find("#divMessageWrapper").show();	// fix for lousy IE's transparency bug when fading in.
				$(this).find("#divBackground").css("opacity", 0).animate({"opacity": 0.7}, 200);	// fix for lousy IE's transparency bug when fading in.
				$(this).find("span.panel-overlay").css({'opacity':0, 'color':'white'}).animate({"opacity": 1}, 200);	// fix for lousy IE's transparency bug when fading in.
				$(this).find("div.InfoLink").css({'opacity':0, 'color':'white'}).animate({"opacity": 1}, 200);	// fix for lousy IE's transparency bug when fading in.
			});
			objCanvasTemplate.find("span.panel-overlay").css({'opacity':0});	// fix for lousy IE's transparency bug when fading in.
			objCanvasTemplate.find("div.InfoLink").css({'opacity':0});	// fix for lousy IE's transparency bug when fading in.
			objCanvasTemplate.find("#divBackground").attr("style", "display: block; position: absolute; z-index: 998; width: 100%; left: 0pt; bottom: 0px;");	// fix for lousy IE's transparency bug when fading in.
		
				
			objCanvasTemplate = null;
		},

        // private
        clearFilmStrip: function() {
			if ( this.m_objDivCanvas != null )
				this.m_objDivCanvas.html("");
			if ( this.m_objUlFilmStrip != null )
				this.m_objUlFilmStrip.html("");
        },

        // private
        getCanvasFitSize: function(p_intWidth, p_intHeight) {
			var intCanvasWidth = parseInt(this.m_objDivCanvasTemplate.css("width"));
			var intCanvasHeight = parseInt(this.m_objDivCanvasTemplate.css("height"));

            if (ShowCaseView.m_strCanvasImageStyle == "stretch") {
                return { "width": intCanvasWidth, "height": intCanvasHeight };
            } else if (ShowCaseView.m_strCanvasImageStyle == "original") {
                return { "width": "", "height": "" };
            } else if (ShowCaseView.m_strCanvasImageStyle == "fit") {
                var intImageScale = Math.min(intCanvasWidth / p_intWidth, intCanvasHeight / p_intHeight);
                var intNewWidth = (p_intWidth * intImageScale);
                var intNewHeight = (p_intHeight * intImageScale);
                var intNewLeft = (intCanvasWidth - (intImageScale * p_intWidth)) / 2;
                var intNewTop = (intCanvasHeight - (intImageScale * p_intHeight)) / 2;

                //Debug("width " + intNewWidth + " height " + intNewHeight  +  " scale "  +  intImageScale  +  " left "  + intNewLeft  +  " top"  + intNewTop);
                return { "width": intNewWidth, "height": intNewHeight, "scale": intImageScale, "left": intNewLeft, "top": intNewTop };
            }
        },

        // private 
        // Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5). 
        // When the SWF is first loaded it will broadcast an unstarted (-1) event. When the video is cued and ready to play it will broadcast a video cued event (5).
        onPlayerStateChange: function(p_intState) {
            switch (p_intState) {
                case 0:
                    this.m_bVideoPlaying = false;
                    this.doAutoTransition();
                    break;
                case 1:
                    this.m_bVideoPlaying = true;
                    break;
                case 2:
                    this.m_bVideoPlaying = true;
                    break;
                case 3:
                    this.m_bVideoPlaying = true;
					this.doAutoTransition();
                    break;
            }
        },

        // public
        test: function() {
            //alert(this.m_objLITemplate.html());

            /*
            this.m_objUlSource.find("li").each( function() {
            alert($(this).html());
            });
            */
        }
    };

// this event handler is called automatically
// the method name is hardcored in google's code, so do not change "onYoutubePlayerReady"
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("ShowCaseYTPlayer"); // the ID must be the one that's playing!! else, it wont work.
	ytplayer.addEventListener("onStateChange", "ShowCaseView.onPlayerStateChange");
}

function getYoutubeVideoThumb(url, size) {
	if (url === null) { return ""; }

	size = (size === null) ? "big" : size;
	var vid;

	results = url.match("[\\?&]v=([^&#]*)");

	vid = getYoutubeVideoIdByUrl(url);

	if (size == "big" )
		return "http://i1.ytimg.com/vi/" + vid + "/hqdefault.jpg";
	else if (size == "small") {
		return "http://img.youtube.com/vi/" + vid + "/2.jpg";
	}
	else {
		return "http://img.youtube.com/vi/" + vid + "/0.jpg";
	}
}

function getYoutubeVideoIdByUrl(p_strURL) {
	var results = p_strURL.match("[\\?&]v=([^&#]*)");
	return (results === null) ? p_strURL : results[1];
}

var _FlowPlayerLicenses = new Array();
_FlowPlayerLicenses["beanfun.com.tw"] = "#@bdaa4d904d5e60a0dc5";
_FlowPlayerLicenses["beanfun.com.hk"] = "#@1ff5fc73b42335e420f";
_FlowPlayerLicenses["beanfun.com.cn"] = "#@4771532c3a9fab1e163";
_FlowPlayerLicenses["beanfun.com.us"] = "#@a00823de96fcaaeba55";
_FlowPlayerLicenses["beanfun.com.jp"] = "#@cedbd02fc9c11dec118";
_FlowPlayerLicenses["beanfun.com.kr"] = "#@020ece74e8939752a7a";
_FlowPlayerLicenses["beanfun.com.eu"] = "#@3e91ed5b1b18629a08e";
_FlowPlayerLicenses["twindex.com.tw"] = "#@3c92b84b0f0bc5c573c";
_FlowPlayerLicenses["gameastor.com"] = "#@6c8f7cf7feace61c01f";
_FlowPlayerLicenses["gameastor.com.tw"] = "#@dc54cb00895d8863d2c";
_FlowPlayerLicenses["beanfun.com"] = "#@7e04160289445b1309a";

function GetFlowPlayerLicense()
{
	var strDomain = document.domain;
	var intDomainIndex = strDomain.indexOf("beanfun.");
	if ( intDomainIndex == -1 ) intDomainIndex = strDomain.indexOf("gameastor.");
	if (intDomainIndex == -1) intDomainIndex = strDomain.indexOf("twindex.");	    
	strDomain = strDomain.substring(intDomainIndex);
	var strKey = (_FlowPlayerLicenses[strDomain] == null) ? _FlowPlayerLicenses["beanfun.com"] : _FlowPlayerLicenses[strDomain];
	return strKey;
}
