﻿

function resize(which, max) {
    var elem = document.getElementById(which);
    if (elem == undefined || elem == null) return false;
    if (max == undefined) max = 100;
    if (elem.width > max) {
        if (elem.width > max) elem.width = max;
        elem.height = elem.height * (max / elem.width);
        elem.width = max;
    }
}

function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) continue;
        var argname = pairs[i].substring(0, pos);
        var value = pairs[i].substring(pos + 1);
        args[argname] = unescape(value);
    }
    return args;
}

function windowPopup(url, w, h, sc) {
    window.open(url, 'shape_pop', config = 'height=' + h + ',width=' + w + ',toolbar=no,menubar=no,resizable=no,location=no,directories=no,status=no,scrollbars=' + sc);
}


function textCounter(field, cntfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
        cntfield.value = maxlimit - field.value.length;
}


var flowplayerobj = null;
function switchVideos(vType, vUrl, vPlayer) {

    // Unload the flowplayer before deleting the element

    if (flowplayerobj != null)
        flowplayerobj.unload();

    // removing the element
    $('#video' + vPlayer).text(' ');
    $('#video' + vPlayer).remove();
    // Creating the element [ #video ] again after removng it.

    $('#player-warp' + vPlayer).append("<div id='video" + vPlayer +"' class='videoscene1'></div>");

    var vType = vType;

    var vUrl = vUrl;

    if (vType == 'youtube') {

        $('#video' + vPlayer).append('<object width="550" height="330"><param name="wmode" value="transparent"></param><param name="movie" value="' + vUrl + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + vUrl + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="550" height="330"></embed></object>');

    }

    else {

        insertFlowPlayer(vUrl, vPlayer);

    }

}

function insertFlowPlayer(url, player) {

    var vUrl = url;
    var vPlayer = player;
    flowplayerobj = $f("video" + vPlayer, { src: "swf/flowplayer-3.1.5.swf", wmode: 'opaque' }, {
        clip: {
            url: vUrl,
            // these two configuration variables does the trick 
            autoPlay: false,
            autoBuffering: true
        },

        plugins: {
            controls: {
                url: 'swf/flowplayer.controls-3.1.5.swf',
                borderRadius: '0px',
                bufferGradient: 'none',
                sliderColor: '#c9c9c9',
                timeBgColor: '#d5d5d5',
                volumeSliderGradient: 'none',
                tooltipTextColor: '#000',
                buttonOverColor: '#BA1010',
                volumeSliderColor: '#aaaaaa',
                progressGradient: 'medium',
                progressColor: '#BA1010',
                bufferColor: '#c78f8e',
                backgroundColor: '#e1e1e1',
                timeColor: '#000',
                sliderGradient: 'none',
                buttonColor: '#000',
                durationColor: '#000',
                tooltipColor: '#d5d5d5',
                height: 25,
                opacity: 1.0
            }
        }
    });

}
