$(document).ready(function(){
    $('a.video img').addClass("png");
    $("a.video").each(function (i) {
        var file=$(this).attr("href");
        $(this).attr("href",'javascript:void(0)');
        if (file.length>0 && file!='#')
        {
            $(this).click(function () {
                OpenVideo('http://'+window.location.host+file);
            });
        }
    });
    
    if (jQuery.browser.safari && intval(jQuery.browser.version)<531)
    {
        //$('ul#navigation-1 li.top').css('margin-right', '12px');
    }
});

function OpenVideo(video, width, height)
{
    if ($('#vwindow').length==0)
    {
        if (!width) width=800;
        if (!height) height=600;
        
        //$('body').append('<div id="vwindow"><embed src="'+video+'" autostart="true" width="'+width+'" height="'+height+'" name="vplayer" id="vplayer"></embed></div>');
        $('body').append('<div id="vwindow" style="width: '+(width+25)+'px; height: '+(height+55)+'px; text-align:center;">  \
<OBJECT ID="vplayer" WIDTH="'+width+'" HEIGHT="'+height+'" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" \
STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject" align="center"> \
<PARAM NAME="FileName" VALUE="'+video+'"> \
<PARAM name="autostart" VALUE="true"> \
<PARAM name="ShowControls" VALUE="true"> \
<param name="ShowStatusBar" value="false"> \
<PARAM name="ShowDisplay" VALUE="false"> \
<EMBED TYPE="application/x-mplayer2" SRC="'+video+'" NAME="vplayer" \
WIDTH="'+width+'" HEIGHT="'+height+'" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="1" align="center"> </EMBED> \
</OBJECT> \
</div> \
');        
        $('#vwindow').append('<div id="wclose"><img src="images/win/wclose.gif" width="110" height="20" alt="" /></div>');
        $('#vwindow').append('<div class="wtl png"></div><div class="wtc png"></div><div class="wtr png"></div>');
        $('#vwindow').append('<div class="wbl png"></div><div class="wbc png"></div><div class="wbr png"></div>');
        $('#vwindow').append('<div class="wl png"></div><div class="wr png"></div>');
        $('#vwindow .wtc, #vwindow .wbc').width($('#vwindow').innerWidth());
        $('#vwindow .wl, #vwindow .wr').height($('#vwindow').innerHeight());
        //$('#vwindow .wtc, #vwindow .wbc').width(width);
        //$('#vwindow .wl, #vwindow .wr').height(height+25);
        
        var left=$(window).width()/2-width/2;
        $('#vwindow').css("left",left);
        var top=$(window).height()/2-height/2;
        $('#vwindow').css("top",top+$(window).scrollTop());       
        
        $("#vwindow #wclose").click(function () {
            try {
                if ($.browser.msie) document.vplayer.stop();
                else $('#vplayer').stop();
            } catch(err){}
            $('#vwindow').remove();
        });
    }
}

function intval( mixed_var, base ) {	// Get the integer value of a variable
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var tmp;

	if( typeof( mixed_var ) == 'string' ){
		tmp = parseInt(mixed_var);
		if(isNaN(tmp)){
			return 0;
		} else{
			return tmp.toString(base || 10);
		}
	} else if( typeof( mixed_var ) == 'number' ){
		return Math.floor(mixed_var);
	} else{
		return 0;
	}
}
