﻿jQuery.embedCampaignEngine = function(options) {
    // set defaults, then extend with 'options' param if passed
    var settings = $.extend({
        codebase: 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
        width: '736',
        height: '289',
        src: 'LandingFlash/ncta',
        quality: 'high',
        pluginspage: 'http://www.adobe.com/go/getflashplayer',
        align: 'middle',
        play: 'true',
        loop: 'true',
        scale: 'showall',
        wmode: 'opaque',
        devicefont: 'false',
        id: 'ncta',
        base: '/LandingFlash/',
        bgcolor: '#ffffff',
        name: 'phase2',
        menu: 'true',
        allowFullScreen: 'false',
        allowScriptAccess: 'sameDomain',
        movie: 'LandingFlash/ncta',
        salign: ''
    }, options || {}); //If no options, pass an empty object

    AC_FL_RunContent(
		'codebase', settings.codebase,
		'width', settings.width,
		'height', settings.height,
		'src', settings.src,
		'quality', settings.quality,
		'pluginspage', settings.pluginspage,
		'align', settings.align,
		'play', settings.play,
		'loop', settings.loop,
		'scale', settings.scale,
		'wmode', settings.wmode,
		'devicefont', settings.devicefont,
		'id', settings.id,
		'base', settings.base,
		'bgcolor', settings.bgcolor,
		'name', settings.name,
		'menu', settings.menu,
		'allowFullScreen', settings.allowFullScreen,
		'allowScriptAccess', settings.allowScriptAccess,
		'movie', settings.movie,
		'salign', settings.salign
		); //end AC code
};

    function loadVideoPanel(videourl) {
        videourl = "/LandingFlash/" + videourl;
        try {
        
        var width = 765;
        var height = 452;
        var videodivx = "75px";
        var videodivy = "155px";
        document.getElementById("videoiframe").src = getIframeUrl(videourl);
        
        document.getElementById("videodiv1").style.display="block";
        document.getElementById("videoiframe").width = width;
        document.getElementById("videoiframe").height = height;
        document.getElementById("videodiv1").style.left = videodivx;
        document.getElementById("videodiv1").style.top = videodivy;
        document.getElementById("videodiv1").style.width = (width-0+92)+"px";
        document.getElementById("videodiv1").style.height = (height-0+101)+"px";
        } catch(e) {alert(e)}
    }

    function closeVideoPanel() {
        document.getElementById("videodiv1").style.display="none";
        document.getElementById("videoiframe").src = "blank.html";
        document.getElementById("videoiframe").width = 1;
        document.getElementById("videoiframe").height = 1;
    }

    function getVideoPath(videourl) {
        var filepath = document.location.protocol+"//"+document.location.hostname+document.location.pathname;
        var folderpath = filepath.substr(0,filepath.lastIndexOf("/"))+"/";
        var videopath = folderpath+videourl;
        return videopath;
    }

    function getIframeUrl(videourl) {
        var filepath = document.location.protocol+"//"+document.location.hostname+document.location.pathname;
        var folderpath = filepath.substr(0,filepath.lastIndexOf("/"))+"/";
        var videopath = folderpath+videourl;
        return folderpath+"flowplayer.html?file="+videopath;
    }
    
    function recordAnalytics(action, target) {
        var analyticsUrl = "LandingFlash/" + action + "/" + target;
        //alert(analyticsUrl);
        pageTracker._trackPageview(analyticsUrl);
    }
        
     var blank = new Image();
     blank.src = 'images/clear.gif';
     
     $(document).ready(function() {
		$(".draggable").draggable({ iframeFix: true });
        closeVideoPanel();
       var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
       if (badBrowser) {
         // get all pngs on page
         $('img[src$=.png]').each(function() {
           if (!this.complete) {
             this.onload = function() { fixPng(this) };
           } else {
             fixPng(this);
           }
         });
       }
     });
     
     function fixPng(png) {
       // get src
       var src = png.src;
       // set width and height
       if (!png.style.width) { png.style.width = $(png).width(); }
       if (!png.style.height) { png.style.height = $(png).height(); }
       // replace by blank image
       png.onload = function() { };
       png.src = blank.src;
       // set filter (display original image)
       png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
     }
