$(document).ready(function() {
	$('#lang')
	.mouseenter(function() {
		$(this).animate({
			top: '0px'
		});
	})
	.mouseleave(function() {
		$(this).animate({
			top: '-23px'
		});			
	});
	
    $('#diashow div.images').cycle({
		fx: 'fade',
		speed: 4000
	});	
    
    $("a.fancybox").fancybox({
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.8,
		'titleShow'			: false,
		'padding'			: 0,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
    
    $('a.fancyboxUrl').each(function(index, element) {
    	var options = {
			'overlayColor'		: '#000',
			'overlayOpacity'	: 0.8,
			'titleShow'			: false,
			'padding'			: 0,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		};
    	
    	if($(element).getUrlParam('height') && $(element).getUrlParam('width')) {
    		options.height = parseInt($(this).getUrlParam('height'));
    		options.width = parseInt($(this).getUrlParam('width'));
    	}
    	
    	$(element).fancybox(options);
    });
    
    $(".accordion").accordion({ 
    	icons: { 'header': 'acc-closed', 'headerSelected': 'acc-open' },
    	active: false,
    	collapsible: true,
    	autoHeight: false
    });
    
    if(self.document.location.hash) {
    	$(".accordion").accordion('option', 'active', $('a[name="' + self.document.location.hash.substring(1) + '"]').parent());
    } 
    
    $('body.contact div.white label').click(function(event) {
    	event.stopPropagation();
    	$(this).siblings('ul').fadeToggle();
    	$(this).parents('div').siblings('div.white').children('ul').fadeOut();
    });
    
    $('body.contact div.white input').click(function(event) {
    	event.stopPropagation();
    });
    
    $('body.contact').click(function(event) {
    	$(this).find('ul').fadeOut();
    });    
    
    $('body.contact div.white ul li').click(function(event) {
    	event.stopPropagation();
    	var value = $(this).children('span').text();
    	$(this).parent('ul').fadeToggle();
    	$(this).parent('ul').siblings('label').fadeOut(
			100, 
			'linear', 
			function() {
				$(this).children('span').text(value);
				$(this).siblings('input').val(value);
			}
		);
    	
    	$(this).parent('ul').siblings('label').fadeIn(300, 'linear');
    });    
});

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
