/* Kaivomestari Javascript */

$(document).ready(function() {
  $('a.outUrl').append('<img src="/files/img/outUrl.gif" alt="Tämä linkki johtaa ulkopuoliselle sivustolle" />');
  
  $('.headTabs a').append('<span></span>');
  $('.greyTabs a').append('<span></span>');
  $('.contactBox').append('<span class="corner"></span>');
  
  $('.extratiedote .hidden').hide();
  
  $('.extratiedote h3').click(function() {
    $(this).parent().find('.hidden').toggle();
  });
  
  /* IE-fixes */
  if(navigator.appName == 'Microsoft Internet Explorer') {
    $('#navi').addClass('ieFix');
  }
  
  setTimeout(function() {
    $('.slideAway').fadeOut('slow');
  }, 1500);
  
  $('.tp_files a.file').each(function() {
    $(this).click(function() {
      this.blur();
      $(this).find('+p').slideToggle('fast');
    });
  });
  
  $('a.mail').each(function() {
    this.href = this.href.replace('poistatama', '');
    $(this).text($(this).text().replace('poistatama', ''));
  });
  
  
  $('.login input.styled').each(function() {
	var def = $(this).val();
	
	$(this).focus(function() {
		if($(this).val() == def) $(this).val('');
	}).blur(function() {
		if($(this).val() == '') $(this).val(def);
	});
  });
});

function pagePrint() {
}

var fontSizeValue = 2;

function pageFontSize(value) {
  fontSizeValue += value;
  
  if(fontSizeValue < 1) fontSizeValue = 1;
  if(fontSizeValue > 4) fontSizeValue = 4;
  
  if(fontSizeValue == 1) {
    $('#root').css('font-size', '11px');
  }
  else if(fontSizeValue == 2) {
    $('#root').css('font-size', '12px');
  }
  else if(fontSizeValue == 3) {
    $('#root').css('font-size', '13px');
  }
  else if(fontSizeValue == 4) {
    $('#root').css('font-size', '14px');
  }
  
  return false;
}

function admin_confirm(url, ask) {
  if(confirm(ask)) {
    location.href = url;
  }
}

function new_window(url, x, y) {
  popup = window.open(url, "popup", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+x+",height="+y+",left=100,top=50");
  popup.focus();
  return false;
}

function vaihda_tila(tila) {
  if(tila == 'auditorio') { num = 1; }
  if(tila == 'liikuntahalli') { num = 2; }
  if(tila == 'neuvotteluhuone') { num = 3; }
  if(tila == 'luokkatilat') { num = 4; }
  if(tila == 'aula_ravintola') { num = 5; }
  
  $('.greyTabs a').not(':eq('+num+')').removeClass('selected');
  $('.greyTabs a:eq('+num+')').addClass('selected');
  
  $('#tilatAjax .pohja').hide();
  $('#tilatAjax .ajax').load('http://www.kaivomestari.fi/vuokrattavat_tilat/'+tila, function() {
    $(this).show();
  });
}

function vaihda_pohja() {
  $('.greyTabs a').not(':first').removeClass('selected');
  $('.greyTabs a:first').addClass('selected');
  
  $('#tilatAjax .ajax').hide();
  $('#tilatAjax .pohja').show();
}

function pagePrint() {
  print();
}
