/**
 * main js-functions
 */

function getViewportSize()
{
    var size = [0, 0];
    if (typeof window.innerWidth != "undefined") 
    {
        size = [window.innerWidth, window.innerHeight];
    }
    else 
        if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) 
        {
            size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
        }
        else 
        {
            size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
        }
    return size;
}

function createFullBrowserFlash()
{
    swfobject.createCSS("html", "height:100%;");
    swfobject.createCSS("body", "height:100%;");
    swfobject.createCSS("#wrapper", "width:100%; height:100%; min-width:770px; min-height:390px; overflow:hidden;");
    window.onresize = function()
    {
        var el = document.getElementById("wrapper");
        var size = getViewportSize();
        el.style.width = size[0] < 1024 ? "1024px" : "100%";
        el.style.height = size[1] < 580 ? "580px" : "100%";
    };
    window.onresize();
}


if (swfobject.hasFlashPlayerVersion("6.0.65")) 
{
    var flashvars = {
        lang: lang
    };
    var params = {
      bgcolor: "#000000",
      allowfullscreen: 'true',
      menu: 'false'  
    };
    var attributes = {
    	id: "flashContent"    	
    };
    var ei = {
        location: 'media/swf/expressInstall.swf', 
        width: '214',
        height: '137',
        params: {
            wmode: 'transparent'
        },
        expressInstallInit: expressInstallInit,
        expressInstallError: errorCallback
    };
    swfobject.embedSWF("Main.swf", "flashContent", "100%", "100%", "9.0.115", ei, flashvars, params, attributes); 
    if (swfobject.hasFlashPlayerVersion("9.0.115")) 
    {
        swfobject.addDomLoadEvent(createFullBrowserFlash);
    }
} 
else 
{
    window.addEvent('domready', function(){
    	makeFlashAlternative();
    });
}

/**
 * Callback-Function from swfobject, when the expressInstall feature didn`t finished properly
 * @param error {String} errorCode
 */
function errorCallback(error) 
{
   makeFlashAlternative();
}

function makeFlashAlternative()
{
    var textSwitch = $('textSwitch');    
    textSwitch.setProperty('class', 'text_flash');
    textSwitch.setHTML(noFlashText);
    new Element('a', {
        'class': 'flashLink',
        'href': 'http://www.adobe.com/go/getflashplayer',
        'target': '_blank'
    }).injectAfter(textSwitch).setHTML(noFlashLink);
    if ($defined($('expressinstall')) == true )
    {
        $('expressinstall').remove();
    }
    $E('html').setStyle('height', 'auto');
    $E('body').setStyle('height', 'auto');
    $('flashContent').setStyle('display', 'block'); //ie-Bug: leaves display 'none'
    $('alternateText').setProperty('class', 'alternativ_text_flash').setHTML(noFlashAlternateText);
    $('alternateLink').setProperties({
        'class': 'alternativ_link_flash',
        'href': alternateTarget
    }).setHTML(noFlashAlternateLink);
}

function expressInstallInit() {
    var isPC = navigator.platform.indexOf('Win') > -1;
    $('wrapper').setStyle('position', 'relative');
    var expressInstall = new Element('div', {
        'id': 'expressinstall'
    }).injectBefore('wrapper');
    var top = new Element('p', {'class': 'expressinstallTop'}).injectInside(expressInstall);
    
    if (!window.ie && (isPC==true) ) {
        var bottom = new Element('p', {'class': 'expressinstallBottom'}).injectInside(expressInstall);             
    }
    var failure = new Element('p', {'class': 'expressinstallFailure'}).injectInside(expressInstall);
    new Element('a', {
        'class': 'flashLinkSmall',
        'href': 'http://www.adobe.com/go/getflashplayer',
        'target': '_blank'
    }).injectInside(expressInstall).setHTML(noFlashLink);
    
    var alternativ_text_flash = new Element('p', {'class': 'alternativ_text_flash'}).injectInside(expressInstall).setHTML(noFlashAlternateText);
    if (window.ie || (isPC==false)) {
        failure.setStyle('margin-top' , 62);             
    }       
    
    new Element('a', {
        'class': 'alternativ_link_flash',
        'href': alternateTarget
    }).injectInside(expressInstall).setHTML(noFlashAlternateLink);
}


/*
var playerVersion = swfobject.getFlashPlayerVersion(); // returns a JavaScript object
var majorVersion = playerVersion.major;
var minor = playerVersion.minor;
var release = playerVersion.release;
alert("Flash Version " + majorVersion + "." + minor + "." + release);
*/

/*
 * Webtrekk
 */
var wt_dm="track.webtrekk.de"; // track url
var wt_ci="825818716393923"; // webtrekk id(s)
var wt_be=""; // content id

////// OPTIONAL
var wt_cg="";

//// click tracking                       
var wt_ln="auto"; // click tracking: (auto|standard|link)
var wt_ln_attribute="";  // optional: for "standard" only
var wt_linktrack_params=""; // optional: for "link" only

//// heatmap tracking
var wt_hm="0"; // activate heatmap tracking
var wt_respoint="global-container";

//// form tracking
var wt_fm=""; // activate form tracking 

//// basket
var wt_ba=""; // products
var wt_co=""; // optional: costs
var wt_qn=""; // optional: quantity
var wt_ca=""; // optional: category
var wt_pi=""; // optional: brand
var wt_st=""; // optional: basket status: (add|conf|view)

//// total order
var wt_ov=""; // total order value
var wt_cr=""; // optional: currency
var wt_oi=""; // optional: order id

//// campaigns
var wt_mc="mid"; // mediacode
var wt_lp=""; // link position
var wt_kw=""; // keyword

//// custom parameter
var wt_pa="";

//// customer id 
var wt_cd="";

//// cookie handling
var wt_cookie=""; // (3|1, 3 is default, 1st or 3rd party cookie)

function sendTracking(val_be, val_cg) {
    wt_be=val_be;
   	if (val_cg) wt_cg=val_cg;
   	if(typeof(wt_sendinfo) != "undefined") wt_sendinfo();    	
}
