/*DIGG BUTTON*/
    (function() {
        var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
        s.type = 'text/javascript';
        s.async = true;
        s.src = 'http://widgets.digg.com/buttons.js';
        s1.parentNode.insertBefore(s, s1);
    })();

    function formatText(index, panel) { return index + ""; }
    $(function (){
        $('.anythingSlider').anythingSlider({
            easing:"easeInOutBack",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay:true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay:6000,                    // How long between slide transitions in AutoPlay mode
            startStopped:false,            // If autoPlay is on, this can force it to start stopped
            animationTime:600,             // How long the slide transition takes
            hashTags:true,                 // Should links change the hashtag in the URL?
            buildNavigation:true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover:true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText:"",             // Start text
            stopText:"Stop",               // Stop text
            navigationFormatter:formatText       // Details at the top of the file on this use (advanced use)
        });
        $("#slide-jump").click(function(){
            $('.anythingSlider').anythingSlider(6);
        });
    });
    
    $(function (){  
        $(".arrow.forward").mouseenter(function(){
          $(this).stop().animate({"right": "-10px"}, 100);
        });
        $(".arrow.forward").mouseleave(function(){
          $(this).stop().animate({"right": "0"}, 50);
        }); 
        $(".arrow.back").mouseenter(function(){
          $(this).stop().animate({"left": "-10px"}, 100);
        });
        $(".arrow.back").mouseleave(function(){
          $(this).stop().animate({"left": "0"}, 50);
        }); 
        $(".arrow.forward").click(function(){
          $(this).stop().delay(400);
        });             
    });
    
// frontpage showreel open
    $(function (e){ 
		$('#play-game').css('cursor', 'pointer');
        $(".video-feat .play, #play-game").click(function(){    
            $('.video-feat .play').stop().delay(250).fadeOut(250);     
            $('#video-close1').delay(500).fadeIn(250);
            $('#video-hidden .center iframe').show();
            $('#video-hidden').slideDown(500, "easeOutBack");
            $('html, body').stop().animate({
                scrollTop: $('#video-hidden .center iframe, #video-hidden .center').offset('').top - 54
            }, 700,'easeInOutExpo');
            e.preventDefault();
        }); 
    });   
// frontpage showreel close	
    $(function (){  
        $("#video-close1").click(function(){        
            $(this).fadeOut(250);
            $('#video-hidden').slideUp(500, "easeInQuad");
            $(".video-feat .play").delay(500).fadeIn(250);
            $('#video-hidden .center iframe').delay(600).attr( 'src' , 'http://player.vimeo.com/video/20782488');
            /*$('#video-hidden .center #showreel').fadeOut(500).delay(500).remove();*/
        }); 
    }); 	
// frontpage twitter list open
    function add_twitter_icon_action ( )
    {
        $(function (e){
            $(".tweets .moveme").click(function(){
                $('.twit-list .moveme1').delay(500).fadeIn(250);
                $('.twit-list').slideDown(500, "easeOutBack");
                $('html, body').stop().animate({
                    scrollTop: $('.twit-list').offset('').top - 40
                }, 700,'easeInOutExpo');
                e.preventDefault();
            }); 
        });
    }
// frontpage twitter list close
    function remove_twitter_icon_action ( )
		{
		$(function (){  
			$(".twit-list .moveme1").click(function(){ 
				$(this).fadeOut(250);
				$('.twit-list').slideUp(250, "easeInQuad");
			}); 
		}); 
	}
    $(function (e){ 
        $(".slide-to-post-comment").click(function(){   
                                                   
            var rel = $(this).attr ( 'rel' );
            var name = $(this).attr ( 'name' );
            var view = $("#view").val ( );
            
            $("#parent_id").val ( rel );
            
            if ( rel > 0 )
            {
                $.ajax({
                    type: "POST",
                    url: "../ajax-get-comment.php",
                    data: "comment_id="+rel+"&postnum="+name+"&view="+view,
                    success: function(msg){
                        $("#parent_hider").removeClass ( 'display-none' );
                        $("#parent_hider").html ( msg );
                    }
                });
            }
            
            $('html, body').stop().animate({
                scrollTop: $('#post-a-comment').offset('').top - 54
            }, 700,'easeInOutExpo');
            e.preventDefault();
        });     
    });         

    $(function(){
        if ( $('#twitter-div-output') )
        {
            $.ajax({
                url: "ajax-homepage-twitter-output.php",
                success: function(data){
                    $('#twitter-div-output').html(data);
                    $('#twitter-div-output').slideDown(500, "easeOutBack");
                    add_twitter_icon_action ( );
					remove_twitter_icon_action();
                }
            });
        }
    });
    
    $(function(){
        if ( $('#tech-news-div-output') )
        {
            $.ajax({
                url: "ajax-tech-rss-output.php",
                success: function(data){
                    $('#tech-news-div-output').html(data);
                    $('#tech-news-div-output').slideDown(500, "easeOutBack");
                }
            });
        }
    });
    
    function iconFade (fadeTrigger, fadeTarget) {
        $(function (){      
            $(fadeTrigger).mouseenter(function(){       
                $(this).children(fadeTarget).stop().fadeTo(200, 1);
            });
            $(fadeTrigger).mouseleave(function(){       
                $(this).children(fadeTarget).stop().fadeTo(100, 0);
            });
        }); 
    };  
	
    function iconFadeBack (fadeTrigger, fadeTarget) {
        $(function (){      
            $(fadeTrigger).mouseenter(function(){       
                $(this).children(fadeTarget).stop().fadeTo(400, 0);
            });
            $(fadeTrigger).mouseleave(function(){       
                $(this).children(fadeTarget).stop().fadeTo(600, 1);
            });
        }); 
    };  	
    
    iconFade('.map', '.two');
    iconFade('.footer .logo', 'img');       
    iconFade('#social-footer a', 'img');    
    iconFade('.video-feat .play', 'img');   
	iconFadeBack('.staff-profile .fleft.mright20', 'img');
    
    
    
    $(function()
    {

          $("a.slide-to-post-comment").attr ( "href", "#" );
        
          $("#comment-form").submit ( function ( )
         {
             
              var data = new Array ( );
             
               $("#comment-form input").each( function ( )
                {
                    data += escape ( $(this).attr ( 'name' ) ) + '=' + escape ( $(this).val ( ) ) + '&';
                });
               
               $("#comment-form textarea").each( function ( )
                {
                    data += escape ( $(this).attr ( 'name' ) ) + '=' + escape ( $(this).val ( ) );
                });
                $.ajax({
                    type: "POST",
                    url: "../ajax-post-comment.php",
                    data: data,
                    success: function(msg){

                        var obj = jQuery.parseJSON(msg);
                        if ( obj.type == 'success' ) { 
                            $("#response").removeClass ( 'error' ); 
						  $("#comment-content").animate({
							opacity: 0
						  }, 500, function() {
							// Animation complete.
						  });							
                            $("#parent_hider").hide ( 'slow' );
                        }

                        $("#response").html(obj.message);
                        $("#response").parent().show( );
                        
                        $(function (e){ 
                            $('html, body').stop().animate({
                                scrollTop: $('#response-slide').offset('').top - 54
                            }, 700,'easeInOutExpo');
                            e.preventDefault();
                        });
                        
                        
                    },
                    error: function(mg){
                        alert ( "Sorry, we could not post your comment. Please try again later" );
                    }
                });
               
               return false;
         });
    });
    


    $(function(){
        $('.swapout-image').delay(5000).each (function(){
            $(this).children(':first').attr('src', $(this).attr('title'));
            $(this).attr('title','');
        });
    });

    $(function(){
        $('#contact_us_form').submit (function(){
            $.ajax({
                url : $('#root-directory').val()+"/ajax-post-contact.php",
                data : "your_name="+escape ( $('#contact_your_name').val() )+
                "&your_email="+escape ( $('#contact_your_email').val() )+
                "&your_message="+escape ( $('#contact_your_message').val() )+
                "&captcha_id="+escape ( $('#contact_captcha_id').val() )+
                "&captcha="+escape ( $('#contact_captcha').val() ),
                cache : false,
                success : function(data){
                    var obj = jQuery.parseJSON(data);
                    if ( obj.type == 'success' ){
                        //$('#contact_us_error_output').slideUp( 'slow' );
                        //$('#contact_us_success_output').html(obj.message).slideDown('slow');
                        /*$('#contact_us_success_output').children('td').html(obj.message);
                        $('#contact_us_success_output').delay(100).slideUp('slow');
                        $('.contact_us_form').slideUp( 'slow' );      */
                        
                        if ( $('#contact_us_error_output td p').length>0 )
                            $('#contact_us_error_output td p').slideUp(500, "easeInOutExpo").parent().parent().hide();
							$('.contact_us_form').animate({
							opacity: 0
							}, 500, function() {
								$('.contact_us_form').addClass('ie-opacity');
							});						
                        $('#contact_us_success_output').removeClass('display-none').children('td').html('<p style="display:none;">'+obj.message+'</p>').children('p').slideDown(500, "easeInOutExpo");
                    }
                    else {
                        //$('#contact_us_error_output').html(obj.message).slideDown('slow');
                        //$('#contact_us_error_output').hide().removeClass('display-none').children('td').html(obj.message).parent().slideDown('slow');
                        //$('#contact_us_error_output').delay(1400).slideDown('slow');
                        if ( $('#contact_us_error_output td p').length>0 )
                            $('#contact_us_error_output td p').slideUp(500, "easeInOutExpo").html(obj.message).slideDown(500, "easeInOutExpo");
                        else
                            $('#contact_us_error_output').removeClass('display-none').children('td').html('<p style="display:none;">'+obj.message+'</p>').children('p').slideDown(500, "easeInOutExpo");
                    }
                }
            });
            return false;
        });
    });     

    $(function(){
        $('#suggest_form').submit (function(){
            $.ajax({
                url : $('#root-directory').val()+"/ajax-post-blog-idea.php",
                data : "your_message="+escape ( $('#suggestion_your_message').val() ) + "&captcha_id=" + escape ( $('#suggestion_captcha_id').val() ) + "&captcha=" + escape ( $('#suggestion_captcha').val() ),
                cache : false,
                success : function(data){
                    var obj = jQuery.parseJSON(data);
                    if ( obj.type == 'success' ){
                        $('#suggest_error_output').slideUp(500, "easeInOutExpo");
                        $('#suggest_success_output').html(obj.message).slideDown(500, "easeInOutExpo");
                        $('.suggest_form').slideUp(500, "easeInOutExpo");
                    }
                    else {
                        $('#suggest_error_output').html(obj.message).slideDown(500, "easeInOutExpo");
                    }
                }
            });  
            return false;
        });
    });
    
    $(function(){
        $('#email-signup-form').submit ( function(){
            $.ajax({
                url : $('#root-directory').val()+"/ajax-save-email.php",
                data : "email="+$('#email-signup-address').val(),
                cache : false,
                success : function(data){
                    $('#email-signup-form').slideUp('fast', function(){$('#email-signup-form').addClass('alert').html('Your email has now been added to our email database').slideDown('fast');});
                }
            });
            return false;
        });
    });


