// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults



function fullscreen() {

	var win = window.open("/de/media/videorecord/play_fullscreen/84", "Fullscreen", "width=400,height=250");

	win.scrollbars.visible == false;

	if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
		sx1 = win.document.all.mybody.offsetWidth;
		sy1 = win.document.all.mybody.offsetHeight;
	}

	sx2 = win.innerWidth;
	sy2 = win.innerHeight;

	sx = sx2;
	sy = sy2;

	if(sx2 == undefined) {
		sx = sx1;
		sy = sy1;
	}


	win.document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="TEST">');

	win.document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
	win.document.writeln('<param name="movie" value="http://localhost:3000/files/flash/player_fs.swf?<%= Time.now.to_i %>" />');
	win.document.writeln('<param name="menu" value="false" />');
	win.document.writeln('<param name="quality" value="high" />');
	win.document.writeln('<param name="scale" value="noscale" />');
	win.document.writeln('<param name="bgcolor" value="#000000" />');
	win.document.writeln('<param name="FlashVars" value="fullscreen=true&size_x='+sx+'&size_y='+sy+'&locale=<%= params[:locale] %>&media_id=<%= params[:id] %>" />');

	win.document.writeln('<embed src="http://localhost:3000/files/flash/player_fs.swf?<%= Time.now.to_i %>" FlashVars="fullscreen=true&size_x='+sx+'&size_y='+sy+'&locale=<%= params[:locale] %>&media_id=<%= params[:id] %>" menu="false" quality="high" scale="noscale" bgcolor="#000000" width="100%" height="100%" name="Unbenannt-1" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');

	win.document.writeln('</object>');


}


// Flash FSCommand
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Verarbeiten aller FSCommand-Meldungen in einem Flash-Film

function audio_record_DoFSCommand(command, args) {
	var audio_recordObj = isInternetExplorer ? document.all.audio_record : document.audio_record;
	//
	// eigener code hier eingeben
	document.getElementById("datafile_name").value = args;
	//
}
// Hook für Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub audio_record_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call audio_record_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
// END Flash FSCommand


function cam_record_DoFSCommand(command, args) {
	var cam_recordObj = isInternetExplorer ? document.all.cam_record : document.cam_record;
	//
	// eigener code hier eingeben
	document.getElementById("datafile_name").value = args;
	//
}
// Hook für Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub cam_record_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call cam_record_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
// END Flash FSCommand


// this is called from video upload
function submit_upload() {
	if (document.getElementById("checkbox_record").checked) {
		document.forms.myupload.submit();
	}
	else if (document.getElementById("checkbox_upload").checked) {
		swFileObject.startUpload();
	}
	else {
		alert('Bitte vorher eine Option auswaehlen!');
	}
}

// this is called from group new or edit
function submit_group() {
	if (document.forms.myupload.video[0].checked) {
		document.forms.myupload.submit();
	}
	else if (document.forms.myupload.video[1].checked) {
		swFileObject.startUpload();
	}
	else if (document.forms.myupload.video[2].checked) {
		document.forms.myupload.submit();
	}
	else if (document.forms.myupload.video[3].checked) {
		alert("jaja. auswaehlen... toll");
	}

	else {
		alert('Bitte vorher eine Option für das Video waehlen!');
	}

}

function collapseHeader(id)
{
//	Element.toggle(id + '_mibutton');
//	Element.toggle(id + '_mabutton');
        Effect.toggle(id + '_content', 'blind', {duration: 0.2});
}

function upd_pos_image(object) {
    list = escape(Sortable.sequence('gallery_images')); 
    list = unescape(list).split(','); 
    
    position = 0;
    list.each(function(index){
        $("image_position_" + index).value = position;
        position++;
    });
}

function rm_gal_image(index) {
  new Effect.Opacity("image_thumbnail_" + index, {duration:0.5, from:1.0, to:0.3});
  $("to_remove_" + index).value = 1;                
  $("rm_btn_" + index).hide();
  $("rc_btn_" + index).show();
  $("ed_btn_" + index).hide();
}

function rc_gal_image(index) {
  new Effect.Opacity("image_thumbnail_" + index, {duration:0.5, from:0.3, to:1.0});
  $("to_remove_" + index).value = 0;                
  $("rm_btn_" + index).show();
  $("rc_btn_" + index).hide();
  $("ed_btn_" + index).show();
}

function hideFlash() {
    Effect.SwitchOff('flash_messages', {duration: 0.3});
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
         
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
         
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

var page_size = false

function showWaitBox() {
    if (page_size == false)
        page_size = getPageSize();
    
    $('loader').style.marginTop = (pageYOffset + (document.body.getHeight()/2) - 35) + 'px';

    $('waitBox').style.height = page_size[1] + 'px';
    $('waitBox').style.display = 'block';
}
function hideWaitBox() {
    window.setTimeout("$('waitBox').style.display = 'none';", 30);
//    Effect.Fade('waitBox', {duration: 0.5});
}

function toogleLanguageBox(buttonId) {
//    Element.setOpacity('languageSelectBox' , 0.9); //IE7 problem...
    Effect.toggle('languageSelectBox', 'blind', { duration: 0.5 });
//    if($(buttonId).src.gsub('lang.png', 'lang_close.png') != $(buttonId).src)
//        $(buttonId).src = $(buttonId).src.gsub('lang.png', 'lang_close.png');
//    else
//        $(buttonId).src = $(buttonId).src.gsub('lang_close.png', 'lang.png');
}
