var pageVideos = {}; //object for video details

(function($) { 


function lpfDialogPosition() {
                var sHeight = $(window).height();
                var sWidth = $(window).width();
                var dHeight = $('.ui-dialog').height();
                var dWidth = $('.ui-dialog').width();
               
                if($.browser.msie && $.browser.version < 8){
                                dWidth = getDialogWidth();
                                $('.ui-dialog').css({'width':dWidth});
                }
               
				var top = (sHeight / 3) - (dHeight / 3) + $(document).scrollTop();
				var left = (sWidth / 2) - (dWidth / 2);
				
				if(top < 24){
					top = 24;	
				}
               
                $('.ui-widget-overlay').css({'z-index':'1000'});
                $('.ui-dialog').css({'top':top, 'left':left, 'z-index':'1001'});
}
function getDialogWidth(){
                var w = 0;
                $('.ui-dialog-content').contents().each(function(){
                                cW = $(this).outerWidth(true);
                                if(cW > w){
                                                w = cW;
                                }
                });          
                return w;
}
function videoContent(vidRef){
	var vidDetails = eval('pageVideos.'+vidRef);
	
	var flashvars = {
		src : vidDetails.src,
		playButtonOverlay : 'false',
		autoPlay : 'true',
		skin : 'http://demand.assets.adobe.com/global/video/flashplayer/adobe.lpf.strobe-media-playback.skin.xml'
	};
	var params = {
			allowFullScreen : 'true',
			allowscriptaccess : 'always'
		};
	var attributes = {};	
	
	$('#lpf-dialog').html('<div class="video-dialog-content"><div id="video-alt-content"><div id="video-alt-content"><h1><img src="http://www.adobe.com/images/icons/alert.gif" width="16" height="16" alt="Alert" />This content requires Flash</h1><p>To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.</p><p class="caption"><a href="http://www.adobe.com/go/getflashplayer" target="_top">Download the free Flash Player now!</a></p><a href="http://www.adobe.com/go/getflashplayer" class="noHover" target="_top"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" width="112" height="33" border="0" /></a></div></div></div>');
	swfobject.embedSWF("http://demand.assets.adobe.com/global/video/flashplayer/adobe.lpf.stobe-media-playback.player.swf", "video-alt-content", vidDetails.width, vidDetails.height, "9.0.0", null, flashvars, params, attributes);
	$('#lpf-dialog').dialog('open')
	$('#lpf-dialog').parent('.ui-dialog').removeAttr('style');
	lpfDialogPosition();
}

$(document).ready(function(){

    $("a").live('click',function() { //intercept click events on a tags
        var linkItem = $(this);
        var linkType = "";
        var uri = "";
        $.each(linkMap, function(key, value) { //check a tag for a class in the linkMap defined above
            if(linkItem.hasClass(key)) { 
                linkType = key;
                uri = value;
            }
        });
        if(linkItem && linkType == "") { //if link doesn't match, let the click-through proceed
            return true;
        } else { //if the link matches, handle with goLink using page vars and query string
            var oid = lpProduct + "_" + linkType + "_" + keyWordCat + "_" + lpLang;
            var mbc = "SEM_PrimaryCTA"; 
            var mbn = "adobe_" + lpLang  + "_" + lpProgram +  "_"  +  lpProduct  + "_"  +  linkType  +  "_clicksuccess";
            goLink(oid,lpEventType,uri,mbc,mbn);
            return false;
        }       
    });
	$('.print-link').click(function(){
		window.print();               
		return false;
	});
	$('#lpf-dialog').dialog({
		autoOpen: false,
		closeText: 'x',
		draggable: false,
		modal: true,
		resizeable: false,
		close: function(event, ui) {
			$('#lpf-dialog').empty();
		}
	});
	$(window).resize(function(){
	    lpfDialogPosition();
	});
	
	$('.ui-widget-overlay').live('click', function(){
	    $('#lpf-dialog').dialog('close');
	});          
	$('.lpf-dialog-button').live('click', function(){
	    $('#lpf-dialog').html($('#'+$(this).attr('rel')).html()).dialog('open');
	    $('#lpf-dialog').parent('.ui-dialog').removeAttr('style');
	    lpfDialogPosition();
	}); 
	 $('.lpf-video-dialog-button').live('click', function(){
		videoContent($(this).attr('rel'));
	});	
	 $('.print-link').click(function(){
	    window.print();               
	    return false;
	 });
	 if(typeof req != "undefined" && req["lpfplay"] != null){
		var vidDetails = eval('pageVideos.'+req["lpfplay"]);
		if(vidDetails != null){
			videoContent(req["lpfplay"])	
		}
	}
});

})(jQuery);
