	var activeslide = 0;
	var sliderinterval = 0;
	var slidertimer = 2500;


$(function(){

	

	$(".postcontent .content a img").parent().addClass("imgattach");
	$(".map").fadeToggle();
		$(".descrip").hide();
	$(".pagenation").hide();
	$(".leftarrow,.rightarrow").hide();
	$("#slideshow").hide();
	$("#image1").one('load', function() {
		
		var hash = parseInt(window.location.hash.slice(1));
		if(hash > 0){
			activeslide = hash;
			slideSwitch(hash);
		}
		$("#slideshow").fadeIn();

		}).each(function() {
			if(this.complete || (jQuery.browser.msie)) 
$(this).trigger("load");
		});

	$(".thumbs ul li.frontimages").fadeTo("slow", 0.3); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	$(".thumbs ul li.frontimages").hover(function(){
		$(this).stop().fadeTo(200, 1.0); // This should set the opacity to 100% on hover
	},function(){
		$(this).stop().fadeTo(200, 0.3); // This should set the opacity back to 30% on mouseout
	});
	
	$("#slider").hover(function(){
		clearTimeout(sliderinterval);						  
		$(".descrip").fadeIn();
		$(".pagenation").fadeIn();
		$(".leftarrow,.rightarrow").fadeIn();
	},function(){
		$(".descrip").fadeOut();
		$(".pagenation").fadeOut();
		$(".leftarrow,.rightarrow").fadeOut();
		//sliderinterval = setInterval( "slideSwitch()", slidertimer );
		})
	
	$(".rightarrow").click(function(){
		clearTimeout(sliderinterval);

		slideSwitch();
	}
	);
	
	$(".leftarrow").click(function(){
		clearTimeout(sliderinterval);

		slideSwitch(activeslide-1);
	}
	);
	
	$(".shares").hover(function(){
		$(".soc",this).stop().animate({height: 20}, 'slow');
	},function(){
		$(".soc",this).stop().animate({height: 0}, 'slow');	
	});

	$(".follows").hover(function(){
		$(".soc1",this).stop().animate({width: 168}, 'slow');
	},function(){
		$(".soc1",this).stop().animate({width: 0}, 'slow');	
	});
	
	$(".clickmap").click(function(){
		$(".map").fadeToggle(function(){
			if($(".map").is(":visible"))
			{
				$(".clickmap span").html("Hide");		
			}else{
				$(".clickmap span").html("Show");			
			}						  
		});
	});
	
	
	$(document).keydown(function(e){
    if (e.keyCode == 39) { 
    		clearTimeout(sliderinterval);

	       	slideSwitch();
              return false;
    	}
    
    if (e.keyCode == 37) { 
    		clearTimeout(sliderinterval);

			slideSwitch(activeslide-1);
	       	return false;
    	}
	});
	
	$(".sliceholder div a").hover(function(){
		$('#'+$(this).parent().attr("class")).attr("src",$(this).parent().attr('id'));
	});

					                    	       
});

function slideSwitch(index) {
    var $active = $('#slideshow li.active');			
    if(index >= 0){
		activeslide = index;
	}
	else if(index <0) {
    	activeslide = $("#slideshow li").length-1;
	}
    else {
    	activeslide = (activeslide+1) == $("#slideshow li").length ? 0 :activeslide+1;
    }
	  window.location.hash = "#"+activeslide;
    var $next =  $("#slideshow li:eq("+activeslide+")");
    $active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active').css({opacity: 0.0});
        });
}

function rotationImages()
{
	/*$(".imgdesc").hide();
	$(".descrip").hide();
	$(".pagenation").hide();
	$(".arrows").hide();
	$(".iactive").fadeIn();*/
}

function validate(type,submitnow) {
        var data = new Array()
        var errors = 0;
        $('.contact-form .text').each(function() {
        if($(this).attr('id') == 'url'){} else {
        	data.push($(this).val());
            if ($(this).attr("name") == "email") {
                if (validateEmail($(this).val())) {
                    $(this).removeClass("contact-error");
                } else {
                    if(submitnow) $(this).addClass("contact-error");
                    errors++;
                }
             }
            else {
                if ($(this).val() == "") {
                    if(submitnow) $(this).addClass("contact-error");
                    errors++;
                } else {
                    $(this).removeClass("contact-error");
                }
            }
        }
        }
        );
        
        if (errors == 0) {
        	if(submitnow){
				sendcontactform();           }
           }
           else{
           		return true;          	
           }
}
    
    
function sendcontactform(){
			var commentform=$('#commentform');
			var infodiv=$('#wdpajax-info');
			$('#wdpajax-info').html('<img class="spinner" src="/wp-content/themes/koldby/images/ajax-loader.gif" />');	
			//serialize and store form data in a variable
			var formdata=commentform.serialize();
			//Add a status message
			//infodiv.html('<p class="wdpajax-loading">Processing...</p>');
			//Extract action URL from commentform
			var formurl=commentform.attr('action');
			//Post Form with data
			$.ajax({
				type: 'post',
				url: formurl,
				data: formdata,
				dataType: 'html',
				error: function(xhr, textStatus, errorThrown){
					$('#send-content').html('SEND');
					if(xhr.status==500){
						var response=xhr.responseText;
						var text=response.split('<p>')[1].split('</p>')[0];
						infodiv.html('<p class="wdpajax-error" >'+text+'</p>');
					}
					else if(xhr.status==403){
						infodiv.html('<p class="wdpajax-error" >Too fast - please try again in a couple of seconds :-)</p>');
					}
					else{
						if(textStatus=='timeout')
							infodiv.html('<p class="wdpajax-error" >Server timeout.. Try again.</p>');
						else
							infodiv.html('<p class="wdpajax-error" >Unknown error</p>');
					}
				},
				success: function(data, textStatus){
				
					if(data=="success"){
						setTimeout(function(){						
						setFormStatus('sent');
						infodiv.html('<div class="wdpajax-fdeesuccess"><span class="emulateLink" onClick="reload()">Click here to see your comment</span></div>');
						},1000);
						}
					else {
						infodiv.html('<p class="wdpajax-error" >Something went wrong. Please try again.</p>');
						}
					commentform.find('textarea[name=comment]').val('');
					commentform.find('input[name=author]').val('');
					commentform.find('input[name=email]').val('');
					commentform.find('input[name=url]').val('');
				}
			});
		}

function validateEmail(email) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return (pattern.test(email));
}

function setFormStatus(newstatus){
	if(newstatus == "sent"){
	$('#send-content').html('Thanks').parent().attr('onclick','return false').addClass('commentdone');
    $('.contact-form .text').each(function() {
    		$(this).attr("disabled", true);
    		$(this).addClass('contact-text-disabled').parent().addClass("contact-disabled");
    	});
    }
    else if(newstatus == "active"){
    	$('.makeable-button').removeClass('disabled-makeable-button');
    }
    else if(newstatus == "disabled"){
    	$('.makeable-button').addClass('disabled-makeable-button');
    }
}

function reload(){
	window.location.hash = "#comments";
	//window.location = $('#permalink').val();
	window.location.reload();
}


