﻿function GetWidth() {
    var x = 0;
    if (self.innerHeight)
    {
            x = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
            x = document.documentElement.clientWidth;
    }
    else if (document.body)
    {
            x = document.body.clientWidth;
    }
    return x;
}

var strSWFPath = ''; 
var strSWFLink = '';
var strWidth = '';
var strHeight = '';
var adsWidth = 0;
var bodyWidth = 0;

function ShowFloatAds(imgLeft, imgRight, heightLeft, heightRight, divAdsLeft, divAdsRight) {
    var intWidthBrowser = 0;
    var intWidthBody = 984;
    var intWidthAds = 0;
    var strInnerHTML = '';

    intWidthBrowser = GetWidth();

    intWidthAds = (intWidthBrowser - intWidthBody) / 2;
    adsWidth = intWidthAds;
    bodyWidth = intWidthBody;
    
    if (imgLeft != '') {
        document.getElementById(divAdsLeft).style.backgroundRepeat = 'no-repeat';
        document.getElementById(divAdsLeft).style.backgroundPosition = 'right top';
        document.getElementById(divAdsLeft).style.cursor = 'pointer';
        document.getElementById(divAdsLeft).style.textAlign = 'right';
        document.getElementById(divAdsLeft).style.padding = '0px';
        document.getElementById(divAdsLeft).style.position = 'fixed';
        document.getElementById(divAdsLeft).style.left = '0px';
        document.getElementById(divAdsLeft).style.top = '0px';
        document.getElementById(divAdsLeft).style.overflow = 'hidden';
        document.getElementById(divAdsLeft).style.width = (intWidthAds - 8) + 'px';
        document.getElementById(divAdsLeft).style.height = heightLeft;
        document.getElementById(divAdsLeft).style.backgroundColor = 'Transparent';
        document.getElementById(divAdsLeft).style.backgroundImage = 'url("' + imgLeft + '")';
    }
    
    if (imgRight != '') {
        document.getElementById(divAdsRight).style.backgroundRepeat = 'no-repeat';
        document.getElementById(divAdsRight).style.cursor = 'pointer';
        document.getElementById(divAdsRight).style.textAlign = 'left';
        document.getElementById(divAdsRight).style.padding = '0px';
        document.getElementById(divAdsRight).style.position = 'fixed';
        document.getElementById(divAdsRight).style.right = '0px';
        document.getElementById(divAdsRight).style.top = '0px';
        document.getElementById(divAdsRight).style.overflow = 'hidden';
        document.getElementById(divAdsRight).style.width = intWidthAds + 'px';
        document.getElementById(divAdsRight).style.height = heightRight;
        document.getElementById(divAdsRight).style.left = parseInt(intWidthAds) + parseInt(intWidthBody) +  'px';
        document.getElementById(divAdsRight).style.backgroundColor = 'Transparent';
            
//        if (imgRight.indexOf('.swf') > -1) {
//            var strSWFContent = CreateSWFBanner(imgRight, '', intWidthAds, heightRight);
//            InitSWFBanner('divAdsRight', strSWFContent);
//        }
//        else {
            
            document.getElementById(divAdsRight).style.backgroundImage = 'url("' + imgRight + '")';
        //}
    }
}


function CreateSWFBanner(strWidth, strHeight) {
    var strLinkVideo = new String();

    strLinkVideo = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="' + strHeight + 'px"';
    strLinkVideo += 'codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=8,0,0,0">';
    strLinkVideo += '<param name="MOVIE" value="' + 'http://images.thegioididong.com/qcao/09_04_2011_12_48_07_demo.swf' + '" />';
    strLinkVideo += '<param name="PLAY" value="true" />';
    strLinkVideo += '<param name="LOOP" value="true" />';
    strLinkVideo += '<param name="QUALITY" value="high" />';
    strLinkVideo += '<param name="SCALE" value="exactfit"/>';
    strLinkVideo += '<param name="FLASHVARS" value="zoomtype=3" />';
    strLinkVideo += '<param name="WMODE" value="transparent" />';
    strLinkVideo += '<embed src="' + 'http://images.thegioididong.com/qcao/09_04_2011_12_48_07_demo.swf' + '" height="' + strHeight + 'px" play="true"';
    strLinkVideo += 'align="" loop="true" quality="high" scale="exactfit" type="application/x-shockwave-flash" flashvars="zoomtype=3" wmode="transparent"';
    strLinkVideo += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
    strLinkVideo += '</embed>';
    strLinkVideo += '</object>';
    
    return strLinkVideo;
}

var intTimeout = 0;

function InitSWFBanner(objCtrl) {
    clearTimeout(intTimeout);
    
    var ctrl = document.getElementById(objCtrl);
    var strBannerContent = CreateSWFBanner('0', '482');
    
    if (ctrl != null) {
        ctrl.innerHTML = strBannerContent;
        ctrl.style.visibility = 'visible';
        ctrl.style.zIndex = '9999';
        ctrl.style.cursor = 'pointer';
        ctrl.style.position = 'absolute';
        ctrl.style.left = parseInt(bodyWidth) +  'px';
        
        intTimeout = setTimeout('RemoveSWFBanner()', 15000);
    }
}

function RemoveSWFBanner() {
    var ctrl = document.getElementById('divAdsSWFBanner');
    
    if (ctrl != null) {
        ctrl.style.visibility = 'hidden';
        ctrl.innerHTML = '';
        ctrl.style.zIndex = '1';
    }
}
