﻿/*****************************************************************************************
*
*  Musiktheorie-Aktuell
*
*  Copyright 2009 by Andreas Helmberger and Ulrich Kaiser
*  Last Modified: 2009-11-08 22:22:00
*
*
*****************************************************************************************/


var template = 
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
    "<head>" +
        "<title>Übung</title>" +
        "<link href=\"/styles/calibration.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\" />" +
        "<link href=\"/styles/masterlayout.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\" />" +
        "<link href=\"/styles/print.css\" rel=\"stylesheet\" type=\"text/css\" media=\"print\" />" +
    "</head>" +
    "<body style=\"margin: 10px 25px;\">" +
        "<div class=\"PrintLink\"><a onclick=\"window.print(); return false;\" href=\"#\">Drucken</a></div>" +
        "<div>{0}</div>" +
    "</body>" +
"</html>";

var win;

var jquery = $(document);

jquery.ready(processExercises);

function processExercises() {

    var exerciseDivs = $(".Exercise");
    exerciseDivs.each(processExercise);

    var exerciseLinks = $(".ExerciseLink a");
    exerciseLinks.each(processExerciseLink);

}

function processExercise() {

    $(this).hide();    
    $(this).before("<div class=\"ExerciseLink\"><a href=\"#\">Übung</a></div>")
}

function processExerciseLink() {

    $(this).click(showPopup);
}

function showPopup() {

    var html = $(this).parent().next().html();
    var doc = template.replace(/\{0\}/, html);

    var width = 800;
    var height = 700;

    var positionX = (screen.availWidth / 2) - (width / 2);
    var positionY = (screen.availHeight / 2) - (height / 2);

    if (win != null) {
        win.close();
    }

    win = window.open("/tutorials/exercise.aspx", "Übung", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, fullscreen=no, width=" + width + ", height=" + height + ", top=" + positionY + ", left=" + positionX);

    win.onload = function() {
        $(".ExerciseContent", win.document).html(html);
        win.focus();
    };

    return false;
}
