﻿$(document).ready(function() {
    $("a.kiosk").click( function() {
        //TODO: track the links deparatelly for the click thorugh here
        
        if (parent && typeof (parent.m_ftbEditorClientId) == "undefined") {
            _bindKioskMode(this);    
            return false;
        }
    });
});


function _bindKioskMode(pThis) {
    var URL = escape(pThis.href);
    var vd = m_virtualDirectory;

    if (typeof (vd) == "undefined" || vd == "")
        vd = "/";    //asume single bar

    if (vd.length > 0 && vd.substring(vd.length - 1, 1) != '/')
        vd += "/";

    var page = vd + "kioskmode.aspx";
    var fullScreen = "fullscreen=no,";
    var size = "";
    var height, width;
    //check if full or partial screen
    
 
    if ( $(pThis).hasClass("kioskFS") ) {
        height = screen.height;
        width = screen.width;
        
        fullScreen = "fullscreen=yes,height=" + height + ",width=" + width + ",";
    }
    else {
        //set size
        var classes = pThis.className;
        
        //split by the space
        var aClass = classes.split(" ");
        
        var i;
        for(i=0;i<aClass.length;i++) {
            var singleClass = aClass[i];
            
            if (_isSizeClass(singleClass)) {
                var aParts = _parseSize(singleClass);
                
                height = aParts[0];
                width = aParts[1];
                
                size = ",height=" + height + ",width=" + width;
            }
        }
    }

    window.open(page + "?p=" + URL, '', fullScreen + 'toolbar=no,resizable=no' + size, false);        
    return false;
}

function _isSizeClass(cssClass) {
    if (cssClass.indexOf("size-") > -1)
        return true;
        
    return false;
}

function _parseRawParams(cssClass) {
    var params = new Array();
    
    if(cssClass!=null)
    {
        //remove the size-
        cssClass = cssClass.replace("size-", "");
        
        //parse the info
        var aSizes = cssClass.split("|");
        var unit = aSizes[2];
        
        params[0] = aSizes[0];
        params[1] = aSizes[1];
        params[2] = aSizes[2];
    }
    
    return params;
}

function _parseSize(cssClass) {
    var params = new Array();
    
    //remove the size-
    cssClass = cssClass.replace("size-", "");
    
    //parse the info
    var aSizes = cssClass.split("|");
    var unit = aSizes[2];
    
    if (unit != "%") {    
        params[0] = aSizes[0];
        params[1] = aSizes[1];
    } else {
        //calculate the % 
        var totalWidth, totalHeight;
        totalHeight = screen.height;
        totalWidth = screen.width;
        
        params[0] = parseInt( (totalHeight * aSizes[0]) / 100, 0);
        params[1] = parseInt( (totalWidth * aSizes[1]) / 100, 0);
    }
   
    
    return params;
}
