/*if(window.onerror){
  window.onerror = 
    function() {
      return true;
    }
  ;
}*/
//window.onerror=function() {return true;};


// Sliderconfig
var slider;
var prev = 0;
var act = 1;
var next = 2;

function timedSlide() {
	clearTimeout(slider);
	try{
  	if (prev != 0) { $('tv'+prev).setStyle({ zIndex: 0 }); }
  	if (prev = next) { $('tv'+prev).setStyle({ width: 0 }); }
  	$('tv'+act).setStyle({ zIndex: 1 });
  	$('tv'+next).setStyle({ zIndex: 2 });
  	if ($('tv'+next).readAttribute('xl') == null && $('tv'+act).readAttribute('xl') == null) {
  		new Effect.Morph('tv'+next, { style: 'width:535px;' }, {duration: 1} );
  	} else if ($('tv'+next).readAttribute('xl') == 1 && $('tv'+act).readAttribute('xl') == 1) {
  		new Effect.Morph('tv'+next, { style: 'width:672px;' }, {duration: 1} );
  	} else if ($('tv'+next).readAttribute('xl') == 1 && $('tv'+act).readAttribute('xl') == null) {
  		new Effect.Morph('tv'+next, { style: 'width:672px;' }, {duration: 1} );
  		new Effect.Morph('bigscreen', { style: 'width:715px;' }, {duration: 1} );
  		new Effect.Move('bigscreen', { x: -137, mode: 'relative' });
  	} else if ($('tv'+next).readAttribute('xl') == null && $('tv'+act).readAttribute('xl') == 1) {
  		new Effect.Morph('tv'+next, { style: 'width:535px;' }, {duration: 1} );
  		new Effect.Morph('tv'+act, { style: 'width:535px;' }, {duration: 1} );
  		new Effect.Morph('bigscreen', { style: 'width:578px;' }, {duration: 1} );
  		new Effect.Move('bigscreen', { x: 137, mode: 'relative' });
  	}
  	if (prev != 0 && prev != next) { new Effect.Morph('tv'+prev, { style: 'width:0px;' }); }
  	prev = act;
  	act = next;
  	next = next+1;
  	if (next == 5) { next = 1 }
	}catch(e){}
	slider = setTimeout("timedSlide()",6000);
}

function setSlide(v) {
	if (act != v) {
		next = v;
		timedSlide();
	}
}

// Menuconfig
var hide = new Array()
function show_menu(tag) {
	clearTimeout(hide[tag]);
	Element.clonePosition($('menu_'+tag), $('m_'+tag), {offsetTop: 18, setWidth: false, setHeight: false} )
	$('menu_'+tag).setStyle({ display: 'inline' });
}
function hide_menu(action) {
	hide[action] = setTimeout("do_hide('"+action+"')",200);
}
function do_hide(tag) {
  //if(console) console.log(tag);
	 $('menu_'+tag).setStyle({ display: 'none' });
}

function update_joa_5() {
  //return;
	ajax =  new Ajax.PeriodicalUpdater(
        'joa_text',		// DIV id must be declared before the method was called
        '/joa/ajax',		// URL
        {				// options
          asynchronous:true,
		      frequency:8,
          method: 'get'
        });
}

function update_joa() {
  return update_joa_5();
	ajax =  new Ajax.PeriodicalUpdater(
        'joa_text',		// DIV id must be declared before the method was called
        '/joa.php?type=utf8',		// URL
        {				// options
        asynchronous:true,
		frequency:5
        });
}

function set_vote(vid) {
	new Ajax.Request('/bildvote/set/'+vid);
}

function webcam_pop(){
  var webcam = window.open('http://www.hitfm.at/content/cam','hitfm_webcam','width=640,height=480');
}

function webradio_click(){
  //window.open('/webradio',null,'width=379,height=70,left=200,top=200');
  //var umfrage = window.open('http://www.marketagent.com/popup/1952/entry_hitfm.asp','_blank','width=610,height=610,left=200,top=350');
  var player = window.open('http://www.hitfm.at/webradio','hitfm_webradio','width=379,height=80,left=200,top=150');
}

function joa_click(){
  window.location.href='http://www.hitfm.at/content/spshow';
}

window.webradio_pop = function(){
  try{
    var player = window.open('','hitfm_webradio','width=379,height=70,left=200,top=150');
    if(player.location != 'http://www.hitfm.at/webradio') player.location = 'http://www.hitfm.at/webradio';
  }catch(e){}
}

// fpbanner

var fpb_loaded = 0;
function fpb_load(){
    var div_fpb = $('fpbanner');
    if(fpb_loaded) return;
    if(!div_fpb) return;
    new Ajax.Request('/home/fpbanner_serve', {
      method: 'get',
      onSuccess: function(transport) {
        div_fpb.innerHTML = transport.responseText;
        fpb_loaded = 1;
        try {
          do_pngfix();
        }catch(e){}
      }
    }); 
}

Event.observe(window, 'load', function() {
  if(fpb_loaded) return;
  try{
    var div_fpb = $('fpbanner');
    var div_sky = $('banner_sky');
    var load_fpb = 0;
    if(div_fpb && div_sky){
      if(div_sky.innerHTML.include('/Right1/Austriacom/default/empty.gif/')) load_fpb = 1;
      if(div_sky.innerHTML.include('?_RM_EMPTY_&amp;" width="1" height="1"')) load_fpb = 1;
      if(div_sky.innerHTML.include('?_RM_EMPTY_&amp;" width=1 height=1')) load_fpb = 1;
      if(typeof(OAS_AD) == "undefined") load_fpb = 1;
    }
    if(load_fpb) fpb_load();
  }catch(e){}
});

// 4 ie6 ...
Element.Methods.getStyle = function(element, style) {
  try{
    element = $(element);
    style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
    var value = element.style[style];
    if (!value && element.currentStyle) value = element.currentStyle[style];

    if (style == 'opacity') {
      if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
        if (value[1]) return parseFloat(value[1]) / 100;
      return 1.0;
    }

    if (value == 'auto') {
      if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
        return element['offset' + style.capitalize()] + 'px';
      return null;
    }
    return value;
  }catch(e){}
  return null;
};

function werbestar_check(form){
  try{
    if(form.bild.value.length < 2){
      alert('Bitte ein Bild angeben.');
      return false;
    }
    if(form.vorname.value.length < 3){
      alert('Bitte Vornamen angeben.');
      return false;
    }
    var regex_email = new RegExp("^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$");
    if(!regex_email.test(form.email.value)){
      alert('Bitte Email angeben.');
      return false;
    }
    if(form.telefon.value.length < 5){
      alert('Bitte Telefonnummer angeben.');
      return false;
    }
    if(form.kommentar.value.length < 5){
      alert('Bitte Kommentar eingeben.');
      return false;
    }
    return true;
  }catch(e){}
  return false;
}
