/* Author: 

*/


jQuery(document).ready(function ($) {

 // lightbox
// Supported file extensions
var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

 var posts = jQuery('.post');
 posts.each(function() {
	 $(this).find(thumbnails).addClass("fancybox").attr('rel','fancybox'+posts.index(this));
 });

 $("a.fancybox").fancybox({
  'titleShow' : false,
  'transitionIn' : 'elastic',
  'transitionOut'	: 'elastic'
 });
  
		jQuery('#contact-form form').submit(function(e){

			//prevent the normal processing
			e.preventDefault();

			//delete the errors (so we don't get duplicates ')
			jQuery("#contact-form .error").remove();

			//declaring and setting vars
			var value, theID, empty_error, email_error, error, emailReg;
			empty_error = '<p class="error">This field is required</p>';
			email_error = '<p class="error">The email you entered is not valid</p>';
			error = false;
			emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;				

			//validating
			jQuery('#contact-form textarea, #contact-form input[type=text]').each(function(){
				value = jQuery(this).val();
				theID = jQuery(this).attr('id');
				if(value == ''){
					jQuery(this).parent().append('<p class="error">'+empty_error+'</p>');
					error = true;
				}
				if(theID == 'c_email' && value != '' && !emailReg.test(value)){
					jQuery(this).parent().append('<p class="error">'+email_error+'</p>');
					error = true;
				}
			});

			//send email and loaded message
			if(error == false){
				jQuery('#contact-form').load('<?php the_permalink(); ?> .email-sent', jQuery('#contact-form form').serialize());
			}

		});


		// Fancybox Vimeo -testi
		
		$("#vimeo-linkki").click(function() {
			$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'title'			: this.title,
				'width'			: 640,
				'height'		: 360,
				'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
				'type'			: 'swf'
			});
	
			return false;
		});

});


$(document).ready(function() {
  
    // set your twitter id
    var user = 'solidangle';
      
    // using jquery built in get json method with twitter api, return only one result
    $.getJSON('http://twitter.com/statuses/user_timeline.json?screen_name=' + user + '&count=1&callback=?', function(data)      {
          
        // result returned
        var tweet = data[0].text;
      
        // process links and reply
        tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) {
            return '<a href="'+url+'">'+url+'</a>';
        }).replace(/B@([_a-z0-9]+)/ig, function(reply) {
            return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
        });
      
        // output the result
        $("#tweet").html(tweet);
    }); 
      
});











