/* VIDEO SECTION */
var videoShow = {

	init : function() {
		videoShow.setEvents();
	},
	setEvents : function() {
        $("a.videoLink").bind("click", videoShow.toggleVideoDiv);
	},
	toggleVideoDiv : function(e) {
		videoShow.elementCode = this.id.replace(/v_/, ""); /* Extract digits of ID */
		videoShow.elementID   = "div#videoContainer_" + videoShow.elementCode;
		if($(videoShow.elementID).is(":hidden")){
			$(videoShow.elementID).slideDown(400, function() {
                /* Animation complete */
                $("a#v_" + videoShow.elementCode).toggleClass("videoLinkActive");
                $("span#videoTextView_" + videoShow.elementCode).toggleClass("hideElement");
                $("span#videoTextClose_" + videoShow.elementCode).toggleClass("hideElement");
				if($(videoShow.elementID).is(":empty")){
                    /* Calculate flash dimensions */
                    if($(videoShow.elementID).width() < 500){
                        videoShow.flashWidth = $(videoShow.elementID).width()-20;
                        videoShow.flashHeight = Math.floor( ($(videoShow.elementID).width()-20) * 0.6145833333 );
                    }else{
                        videoShow.flashWidth = 480;
                        videoShow.flashHeight = 295;
                    }
					videoShow.elementVideo = '<object width="' + videoShow.flashWidth + '" height="' + videoShow.flashHeight + '"><param name="movie" value="http://www.youtube.com/v/' + videoShow.elementCode + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoShow.elementCode + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + videoShow.flashWidth + '" height="' + videoShow.flashHeight + '"></embed></object>';
					$(videoShow.elementID).html(videoShow.elementVideo);
				}
			});
		}else{
			$(videoShow.elementID).slideUp(400, function() {
				/* Animation complete */
                $("a#v_" + videoShow.elementCode).toggleClass("videoLinkActive");
                $("span#videoTextView_" + videoShow.elementCode).toggleClass("hideElement");
                $("span#videoTextClose_" + videoShow.elementCode).toggleClass("hideElement");
			});
		}
        return false;
	}

}

$(document).ready(function(){
	videoShow.init();
});
