
var newWindow = newWindow || {};
newWindow.popup = newWindow.popup || {};

/**
 * Open popup window
 * @param {Object} href
 * @param {Object} params
 * @return {WindowObjectReference}
 */

newWindow.open = function (href, params)
{
    // Defaults (don't leave it to the browser)
    var defaultParams = {
        "width":       "810",   // Window width
        "height":      "600",   // Window height 
        "top":         "0",     // Y offset (in pixels) from top of screen
        "left":        "0",     // X offset (in pixels) from left side of screen
        "directories": "no",    // Show directories/Links bar?
        "location":    "no",    // Show location/address bar?
        "resizeable":  "yes",   // Make the window resizable?
        "menubar":     "no",    // Show the menu bar?
        "toolbar":     "no",    // Show the tool (Back button etc.) bar?
        "scrollbars":  "yes",   // Show scrollbars?
        "status":      "no"     // Show the status bar?
    };
    
    var windowName = params["windowName"] || "new_window";
    
    var i, useParams = "";
    
 
    for (i in defaultParams)
    {
        useParams += (useParams === "") ? "" : ",";
        useParams += i + "=";
        useParams += params[i] || defaultParams[i];
    }
    
    return window.open(href, windowName, useParams);
};



$(function(){ 
    wirePopups ();
});

function wirePopups () {
    $("a.popup").each(function (i){
		
        $(this).click(function(event) {
            
            event.preventDefault();
    
            var params = $(this).data("popup") || {};
        

            if ($(this).attr("target"))
            {
                params.windowName = $(this).attr("target");
            }
        
            // Pop up the window
            var windowObject = newWindow.open(this.href, params);
			
            // Save the window object for other code to use
            $(this).data("windowObject", windowObject);
        });
    });
}

function flashPop(url,videoName)
 {
  transWindow = window.open (url,"transwindow","location=1,status=1,scrollbars=yes,width=800,height=600");
  transWindow.moveTo(0,0);
  tracker.track("read transcript",{ "video name":videoName });
 } 