/* Author: osynlig.se */
$(document).ready(function() {
	
	/*Medlemskap i handelskammaren formulär*/
		
		$('.submit-new-member').click(function(e) {
			e.preventDefault();
			
			company = $('#company').val();
			visit_address = $('#visit-address').val();
			mail_adress = $('#mail-adress').val();
			postalcode = $('#postalcode').val();
			phone = $('#phone').val();
			fax = $('#fax').val();
			email = $('#membership #e-mail').val();
			website = $('#website').val();
			company_leader = $('#company-leader').val();
			leader_email = $('#leader-email').val();
			contact = $('#contact').val();
			contact_email = $('#contact-email').val();
			
			/*if(company != '' && visit_adress != '' && mail_address != '' && postalcode != '' && phone != '' && fax != '' email != '') {
				// Form validation */
  			$('#membership').submit();
			
			/*
			} else { 
				alert('Var vänlig fyll i alla uppgifter');
			} */
			
			
		});
		
			
	/*Setup menu effects*/
	
	$('.menu-item').children('ul').hide();
	$('.current-menu-item').children('ul').show();
	$('.current-menu-ancestor').children().show();
	
	$('.menu-item').hover(
		function() {
			$('.current-menu-ancestor').children('ul').hide();
			$('.current-menu-item').children('ul').hide();
				
			$(this).children().show();
		},
		function() {
			$(this).children('ul').hide();
			$('.current-menu-ancestor').children('ul').show();
			$('.current-menu-item').children('ul').show();
		}
		
	);
	
		
	//Focus-effect
	$('#email').focus(function() {
			if($(this).val() == 'E-postadress...')
				$(this).val('');
			}).focusout(function() {
			if($(this).val() == '')
				$(this).val('E-postadress...');
		});
		
	//Fancybox youtube in sidebar
	$("#youtube").click(function() {
	
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'			: 'transparent',
			'allowfullscreen'	: 'true'
			}
			
		});

	return false;
	});
	
	$('.vimeo').fancybox();
	
	
	//Prenumerera på nyhetsbrev
	$('#submit-button').click(function(e) {
		e.preventDefault();
		if($('#email').val() == '' || $('#email').val() == 'E-postadress...') {
			alert('Var vänlig fyll i din e-postadress.');
		} else {
			var email = $('#email').val();
			var dataString = '&email=' + email;
			$.ajax({
				type: "POST",
				url: "wp-content/themes/Midchamber/subscribe-submit.php",
				data: dataString,
				success: function() {
					$('.sidebar-box-form').empty();
					$('.sidebar-box-form').append('<p>Tack för din anmälan!</p>');
				}
			});			
			
		}
		
	});
	
});
