(function($) {
    $(document).ready(function() {
	    $('.moc_flash_item').click(

		    function(event) {
			    var flvfile = $(this).attr("nv:flvfile");
			    $('.moc_flash_modal',this).modal({persist: false, onClose: function(dialog) {
					    $.modal.close();
				    },
				    onShow: function(dialog) {

					    loadMovie(this,flvfile);
				    }
			    });
			    event.stopPropagation();

		    }
	    );

	    $('.tt_news_image').click(

		    function(event) {
			    //console.log(event);
			    image = this;
			    var flvfile = $(this).attr("nv:flvfile");
			    var parentpage = $(this).attr("nv:parentpage");
			    $('.moc_flash_modal',this).modal({persist: false, onClose: function(dialog) {
					    $.modal.close();
				    },
				    onShow: function(dialog) {
					    //console.log(dialog);
					    loadMovie(image,flvfile,parentpage);
				    }
			    });
			    event.stopPropagation();
    //			$("embed",$("#modalContainer")).attr("width",870);
		    }

	    );


		    /**/
	    //This is to disable the link i LATEST LIST!
	    //$('.moc_flash_modal').parent("div.tt_news_image").parent("a").attr("href","#");
	    $('.moc_flash_modal').parents("div.news-latest-image-wrap").children("a").attr("href","#");
	    //$('a',$('.moc_flash_modal').parent("div.tt_news_image")).attr("href","#");
	    //$('a',$('.moc_flash_modal').parent("div.tt_news_image").parent("div")).attr("href","#");

    });
    function loadMovie(parent,flvfile,parentPage) {
	    $.ajax({
	      type: "GET",
	      url: 'index.php?eID=tx_filestats',
	      data: 'file='+flvfile+'&parentpage='+parentPage,
	      dataType: "script"
	     });
	     /**/

	    var player = $(".flashplayer_container",$("#modalContainer"));
		    //************ END LOAD FLASH *************//
					    var flashvars = {
						    flvfile:  flvfile
					    };
					    var params = {

					    };
					    var attributes = {
					      id: "flashplayer",
					      name: "flashplayer"
					    };
    //					$("#flashplayer_container").html('<div id="flashplayer_container_inner">Replace me</div>');
					    player.html('<div id="flashplayer_container_inner">Replace me</div>');
					    swfobject.embedSWF("/typo3conf/ext/moc_flash/flashplayerv12.swf", "flashplayer_container_inner", "620", "348", "9.0.0","/typo3conf/ext/moc_flash/expressInstall.swf",flashvars, params, attributes);
    //					window.document.flashplayer.calledFromJs();
		    //************ END LOAD FLASH *************//
    }
    /*
    var versionCheckOn = false;
    function checkVersion(theVersionArray){
	    var reqMajorVersion = 9;
	    var reqMinorVersion = 0;
	    var reqRevisionNumber = 0;
	    if(!versionCheckOn){
		    versionCheckOn = true;
		    if(theVersionArray["major"] >= reqMajorVersion && theVersionArray["minor"] >= reqMinorVersion && theVersionArray["rev"] >= reqRevisionNumber){
			    return true;
		    }
		    else{
			    $("#flashversion").show();
			    return false;
		    }
	    }
    }
    /**/
})(jQuery);
