/* Copyright 2011. Roberts Pauls */

// Init Functions
$(document).ready( function(){
	
// Comon UI Elements
	$(".button-submit").click(function() {
		$(".wpcf7 input.text").each(function(){
			if(!$(this).hasClass("focus")){ $(this).val(""); }
		});
		$(this).parents("form").submit();
		$(".wpcf7 input.text").each(function(){
			$(this).focus();
			$(this).blur();
		});
	});

// Input Elements
	swapValue = [];
	$("input.text").each(function(i){
	   swapValue[i] = $(this).val();
	   $(this).focus(function(){
		  if ($(this).val() == swapValue[i]) {
			$(this).val("");
		  }
		  $(this).addClass("focus");
	   }).blur(function(){
		  if ($.trim($(this).val()) == "") {
			$(this).val(swapValue[i]);
			$(this).removeClass("focus");
		  }
	   });
	});
	swappValue = [];
	$("textarea.text").each(function(i){
	   swappValue[i] = $(this).html();
	   $(this).focus(function(){
		  if ($(this).html() == swappValue[i]) {
			$(this).html("");
		  }
		  $(this).addClass("focus");
	   }).blur(function(){
		  if ($(this).val() == "") {
			$(this).html(swappValue[i]);
		 	$(this).removeClass("focus");
		  }
	   });
	});

	
// Main Menu
	$("#menu-main ul li:last").css("background","none");
	// Dynamic Main Menu
	/*	var menuelemwidth = 0;
		var menuelemsumwidth = 940;
		var menuelemcount = $("#menu-main ul li").size();
		var menuelemwidth = Math.round(menuelemsumwidth / menuelemcount);
		var somepixels = menuelemsumwidth - menuelemwidth * menuelemcount;
		for (i=0;i<menuelemcount;i++){
			$("#menu-main ul li:eq("+i+")").css("width", menuelemwidth).css("padding", "0");
		}
		$("#menu-main ul li:last").css("width", menuelemwidth + somepixels);
		*/
	
	
// Slides
	$(function(){
		// Set starting slide to 1
		var startSlide = 1;
		// Get slide number if it exists
		/*if (window.location.hash) {
			startSlide = window.location.hash.replace('#','');
		}*/
		// Initialize Slides
		$('#slides').slides({
			preload: true,
			preloadImage: 'img/body/loading.gif',
			generatePagination: true,
			play: 3900,
			pause: 900,
			hoverPause: true,
			// Get the starting slide
			start: startSlide,
			/*animationComplete: function(current){
				// Set the slide number as a hash
				window.location.hash = '#' + current;
			}*/
		});
		});	

// Footer Menu
	$("#footer-menu ul li:last").css("border","none");


// Expand
	$(".expand ul li").css("cursor","pointer");
	$(".expand blockquote").css("display","none");
	$(".expand ul li").click(function() {
		if ($(this).parent().next("blockquote").css("display") == "none") {
			$(".expand blockquote").slideUp();
			$(this).parent().next("blockquote").slideToggle();
		} else {
			$(".expand blockquote").slideUp();
		}
	});
	$(".expand .more").click(function() {
		$(this).hide();
		$(".expand blockquote").slideDown();
	});

});

