// JavaScript Document



function loadContent(id){
	$("#content").load( "works.html #" + id,function(){
		$("#loading").fadeOut("slow"); 
		$("#content_loader").modal({containerCss: { width:800,height:560 },
		                            dataCss: { width: 760,height:520,padding: 20 },
									
                                    opacity:95,
	                                overlayCss: {backgroundColor:"#333"},
	                                overlayClose: true,
	                                onOpen: function (dialog) {
		                                         
		                                    	dialog.overlay.fadeIn('slow',function(){
			                                            dialog.container.show(function(){
															dialog.data.fadeIn("slow");
															});
			                                             })},
	                                onShow: function(){
		                               
		                            	$(".images").cycle({
											                next: "#next",
															prev: "#prev"
											});
		                               }	
		
									});//modal end 
		});//load end
	
}//end



	
	
	



//send mail
function send(datastr){
	$.ajax({
		type: "POST",
		url: "php/mailer.php",
		data: datastr,
		cache: false,
		success: function(html){
			$("#response").fadeIn("slow");
			$("#response").html(html);
			setTimeout('$("#form").fadeOut("slow")',2000);
			}
	});
}
//end functions



$(document).ready(function(){
	
	
	//video go
	$('.video').click(function(e) {
		e.preventDefault();
		$("#video_loading").show();
		var target_id = $(this).attr("id");
		
		$("#captures div").hide();
		$("#captures div").filter(this.hash).show();
		
    $("#video-js-box").empty().append('<video id="'+ target_id +'" class="video-js" width="440" height="330" controls poster="http://www.kristofferlindfors.com/images/'+ target_id +'.png"><source src="http://www.kristofferlindfors.com/video/'+ target_id +'.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' /><source src="http://www.kristofferlindfors.com/video/'+target_id +'.ogv" type=\'video/ogg; codecs="theora, vorbis"\' /><object class="vjs-flash-fallback" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300" id="player1" name="player1"><param name="movie" value="jwplayer/player.swf"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="flashvars" value="file=http://www.kristofferlindfors.com/video/'+ target_id +'.mp4&image=http://www.kristofferlindfors.com/images/'+target_id+'.png&dock=true"></object></video>');
	          
		VideoJS.setupAllWhenReady();
		VideoJS.setup(target_id);
		$("div#holder div#wrapper ").modal({ 
		                            containerCss: { width:700, backgroundColor: "#222222", padding:20 },
		                            dataCss : { },
		                            opacity:95,
									maxHeight: 600,
	                                overlayCss: {backgroundColor:"#333"},
	                                overlayClose: true,
									closeHTML: "<a href='#'>CLOSE</a>",
									onShow: function(){
										$("#video_loading").fadeOut()
										$(".simplemodal-close").click(function(){
											
											$("#video-js-box").empty();
											
											});
										}
								
									
								  });//modal end
			
			 });//click end
	
	//cycle front gallery
	$("#tab1 .image_holder").cycle();
	
	
	$("ul#work_thumbs a").click(function(e){
			e.preventDefault();
			$("#loading").show();
			loadContent($(this).attr("id"));
		
		});
		
		
		$("#close").click(function(){
			$(".images").cycle("stop");
			$("#content").children().remove();
		
		});
		
		//tabs
		 var tabContainers = $('div#tabs_container > div');
        tabContainers.hide();
  
        $('div#tabs_container > div:first').show();
        $('ul#menu a:first').addClass("active_link");
    
        $('ul#menu a').click(function () {
			
			if($(this).is(".front_page")){$("#tab1 .image_holer").cycle();}
			else{$("#tab1 .image_holer").cycle("stop");}
			
			if(!$(this).is(".active_link")){
        tabContainers.hide().filter(this.hash).fadeIn("slow");
        
        	$('ul#menu li a').removeClass('active_link');
        	$(this).addClass('active_link');
			}
        return false;
    });
		
		//mail
		$("#submit").click(function(){
			var valid = "";
			var isr = ' is required.';
			var name = $("#name").val();
			var mail = $("#email").val();
			var text = $("#msg").val();
			if (name.length<1) {
				valid += '<br />Name'+isr;
			}
			if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
				valid += '<br />A valid Email'+isr;
			}

			if (text.length<1) {
				valid += '<br />Text'+isr;
			}
			if (valid!="") {
				$("#response").fadeIn("slow");
				$("#response").html(valid);
			}
			else {
				var datastr ='name=' + name + '&email=' + mail + '&msg=' + text;
				$("#response").css("display", "block");
				$("#response").html("Sending message …. ");
				$("#response").fadeIn("slow");
				setTimeout("send('"+datastr+"')",2000);
			}
			return false;
		});



});//ready end




	

