// JavaScript Document
function selSlide(){
    var thisNum = $(this).parent('.dropSel').find('.selDropList').attr('id').split('_')[1];
    $('#selDropList_'+thisNum).slideDown(150);
    $('body').click(function(){$('#selDropList_'+thisNum).css('display','none');});
}
function setSel(){
    var thisNum = $(this).parent().attr('id').split('_')[1];
    $('#selDropList_sel_'+thisNum+' option').removeAttr('selected');
    var sel = $(this).attr('value');
    $('#selDropList_sel_'+thisNum+' option[value="'+sel+'"]').attr('selected','selected');
    $('#selDropList_'+thisNum).css('display','none');
    $('#selDrop_'+thisNum+' span').html($(this).html());
    $('#selDrop_'+thisNum+' span').click(function(){$(this).html('');});
} 

function setSel2(){
    var thisNum = $(this).parent().attr('id').split('_')[1];
    $('#selDropList_sel_'+thisNum+' option').removeAttr('selected');
    var sel = $(this).attr('value');
    $('#selDropList_sel_'+thisNum+' option[value="'+sel+'"]').attr('selected','selected');
    $('#selDropList_'+thisNum).css('display','none');
    $('#selDrop_'+thisNum+' span').html('Valitse');
    $('#selDrop_'+thisNum+' span').click(function(){$(this).html('');});
} 


function setPagerPosition(){
    var pager = $('#scrollerPagerCont');
    var pagerWidth = $('#scrollerPagerCont').width();
    var offset = (pagerWidth/2);
    var fromLeft = (240 - offset);
    pager.css("left", fromLeft);
    
}

function tabSlide(){
    var prevCont = $('#tabs div.active').attr('id').split('_')[1];
    if($(this).parents('div:eq(1)').attr('class')=='active'){return;}
    var tabNum = $(this).attr('class').split('_')[1];
    var height = $('#content_'+tabNum).height();
    $('#tabs div').removeClass('active');
    $(this).parents('div:eq(0)').addClass('active');
    //$('#contentContainer').css('height', height+'px');
    $('#content_'+prevCont).removeClass('active');
    $('#content_'+tabNum).addClass('active');
} 

function dropDown(val){
  var theList = $(val).parent().children('.optionList');
  var thisSel='';
  if($(theList).css('display')=='none'){
    $(theList).slideDown(150);
    $(theList).children('li').click(function(){
      thisSel=$(this).attr('rel');
      
      $(val).parent().children('.optionList_sel').children('option').each(function(){
        if($(this).attr('value')==thisSel){
          $(this).attr('selected','selected');
        }else{
          $(this).removeAttr('selected');
        }
      });
      $(val).html($(this).html());
      $(theList).slideUp(150);
    });
  }else{
    $(theList).slideUp(150);
  }
}

function checkSelectedRadioValue(){
  
  var value; //1 = Sähköposti, 2 = Puhelin, 0 = Ei vastausta
  var checkInputValue;
  value = $('.checkRadio input:radio:checked').val();
  
  if(value == 1)
  {
    checkInputValue = $('.checkRadioEmail input:text').val();
    if(checkInputValue == '')
    {
      alert("Anna sähköpostiosoitteesi kiitos.");
      return false;
    }
  }
  else if(value == 2)
  {
    checkInputValue = $('.checkRadioPhone input:text').val();
    if(checkInputValue == '')
    {
      alert("Anna puhelinnumerosi kiitos.");
      return false;
    }
  }
}

function checkIfContactPhoneSelected(){
  
  if ($('.checkCheck input:checkbox').is(':checked') )
  {
    checkInputValue = $('.checkRadioPhone input:text').val();
    if(checkInputValue == '')
    {
      alert("Anna puhelinnumerosi kiitos.");
      return false;
    }
  }  
}


//Näin toimii kulmat FF:lläkin
$.fn.corner.defaults.useNative = false;


$(document).ready(function() {
    $('#frontScroller').cycle({
        fx: 'fade',
        speed: 800, // transition speed
        timeout: 4000, // wait
        slideExpr: 'li',
        prev: '#scrollLeft',
        next: '#scrollRight',
        cleartypeNoBg: true,
        pager: '#scrollerPagerCont',
        pause: 1,
        
        pagerAnchorBuilder: function() { 
        return '<a href="#"></a>'; 
    }
    }); 
    setPagerPosition();
    
    
    // Increase Font Size
    $(".increaseFont").click(function(){
        var currentFontSize = $('p').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum+2;
        if(newFontSize > 17)
        {
            newFontSize = 18;
        }
        $('p').css('font-size', newFontSize);
        $('label').css('font-size', newFontSize);
        $('#centerContentArea li:not(.menuThird li)').css('font-size', newFontSize);
        return false;
    });
    // Decrease Font Size
    $(".decreaseFont").click(function(){
        var currentFontSize = $('p').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum-2;
        if(newFontSize < 12)
        {
            newFontSize = 12;
        }
        $('p').css('font-size', newFontSize);
        $('label').css('font-size', newFontSize);
        $('#centerContentArea li:not(.menuThird li)').css('font-size', newFontSize);
        return false;
    });

    $('#searchForm #searchText').focus(function () {
      if($('#searchForm #fieldTargeted').val() == 0){
        $(this).val('');
      }
      $('#searchForm #fieldTargeted').val('1');
    });
    $('#searchForm #searchText').blur(function () {
      if($('#searchForm #searchText').val() == ''){
        $(this).val($('#searchForm #fieldOriginalText').val()); 
        $('#searchForm #fieldTargeted').val('0');
      }
    });
    
    
    $('.selectOptions span').click(function(){
        dropDown(this);
      });
      
    $(function() {
		$(".datepicker input").datepicker({changeYear: true, changeMonth: true, monthNamesShort: ['Tam','Hel','Maa','Huh','Tou','Kes','Hei','Elo','Syy','Lok','Mar','Jou'], dayNamesMin: ['Su', 'Ma', 'Ti', 'Ke', 'To', 'Pe', 'La'], showButtonPanel: false, dateFormat: 'dd.mm.yy', prevText: '', nextText: '', monthNames: ['Tammikuu','Helmikuu','Maaliskuu','Huhtikuu','Toukokuu','Kesäkuu','Heinäkuu','Elokuu','Syyskuu','Lokakuu','Marraskuu','Joulukuu']});
	});
	
	$('.rounded .attribute-image').corner("8px");
	$('.rounded_fixed .attribute-image').corner("8px");
  
  /*$('.faqBox .heading').toggle(function() {
    //var boxes = $('.faqBox .content');
    //var headings = $('.faqBox .heading');
    //var opened = headings.find('a.closeFaqBox');
    //opened.removeClass('closeFaqBox');
    //opened.addClass('openFaqBox');
    //boxes.hide();
    var content = $(this).parent().find('.content');
    $('this a').removeClass('openFaqBox');
    $('this a').addClass('closeFaqBox');
    content.show();
  }, function() {
    var content = $(this).parent().find('.content');
    $('this a').removeClass('closeFaqBox');
    $('this a').addClass('openFaqBox');
    content.hide();   
  });*/
   
  $('.faqBox .heading').click(function(){
    openFaqBox(this);
  });
  
  $('a.removeFile').click(function(){
    $('input.removableFile').val('');
  });
});

function openFaqBox(val){
  var content = $(val).parent().find('.content');
  if ( content.is(':visible') ) {
    content.hide();
    $(val).find('a').addClass('openFaqBox');
    $(val).find('a').removeClass('closeFaqBox');
    return false;
  }
  var boxes = $('.faqBox .content');
  var headings = $('.faqBox .heading');
  var opened = headings.find('a.closeFaqBox');
  opened.removeClass('closeFaqBox');
  opened.addClass('openFaqBox');
  boxes.hide();
  $(val).find('a').removeClass('openFaqBox');
  $(val).find('a').addClass('closeFaqBox');
  content.show();
}

hs.graphicsDir = '/extension/nvkymenlaaksonsahko/design/nvkymenlaaksonsahko/images/highslide/';
hs.wrapperClassName = 'draggable-header';
hs.width = 700;
hs.showCredits = false;
hs.dragByHeading = false;
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.dimmingDuration = 250;
hs.dimmingOpacity = 0.75;
hs.expandDuration = 250;
hs.align = 'center';
hs.lang = {
  closeText : 'Sulje',
  closeTitle : 'Sulje',
	loadingText : '',
	creditsText : ''
};

function NaytaLayer(lay){

  <!-- Opera bugi ... -->
  PiilotaLayer('lay1');
  PiilotaLayer('lay2');
  PiilotaLayer('lay3');
  <!-- ... Opera bugi -->
  
  if (document.layers) document.layers[lay].visibility = 'visible';
  else if (document.all) document.all[lay].style.visibility = 'visible';
  else document.getElementById(lay).style.visibility = 'visible';
}

function PiilotaLayer(lay){
if (document.layers) document.layers[lay].visibility = 'hidden';
else if (document.all) document.all[lay].style.visibility = 'hidden';
else document.getElementById(lay).style.visibility = 'hidden';
}
