// JavaScript Document
Cufon.replace('h2, h3, h1, #searchform label, .footer, .videoGal p, .formPan h3, .innerHeader h2', { fontFamily: 'Grandesign Neue Serif', hover: true });
Cufon.replace('.topHeader ul > li', { fontFamily: 'Grandesign Neue Serif', hover: true, hoverables: {li: true}, ignore: {div: true}}); 
Cufon.replace('.footer ul > li', { fontFamily: 'Grandesign Neue Serif', hover: true, hoverables: {li: true}, ignore: {div: true}}); 
//Cufon.replace('h2', { fontFamily: 'Myriad Pro' });

$(document).ready(function() {
    
    $('#ffwd_login_button').live('click', function() {
      
      var user_email = $('#ffwd_login_user_email').val();
      var user_pass  = $('#ffwd_login_user_pass').val();
      var user_page  = $('#ffwd_login_page').val();
      var user_login = user_email;
      
      $.post("/wp-content/themes/karl-george/wp-ffwd-login.php",{action: 'register', user_page: user_page, user_email: user_email, user_pass: user_pass, user_login: user_login},
      function(data){
        if (data.success == 'true') {
          
          
          window.location = data.page;
        } else {
          $('#ffwd_login_error').html(data.error);        
        }
      },'json');
    });
    
    $('#ffwd_reg_user_email').bind('keydown',function(e){
      var user_email = $('#ffwd_reg_user_email').val();
      var user_login = user_email;
      
      if (e.keyCode == 13) {
        
        if (user_email.length < 1) {
          $('#reg_message').html('You must enter a username');  
        } else {
          $.post("/wp-content/themes/karl-george/wp-ffwd-register-start.php",{action: 'register', user_email: user_email, user_login: user_login},
          function(data){
            if (data.success == 'true') {
              $('#signupForm').submit();
            } else {
              $('#reg_message').html(data.error);        
            }
          },'json');
        }
        return false;
      }
    });
    
    $('#ffwd_login_user_pass').bind('keydown',function(e){
      var user_email = $('#ffwd_login_user_email').val();
      var user_pass  = $('#ffwd_login_user_pass').val();
      var user_login = user_email;
      
      if (e.keyCode == 13) {
        
        if (user_email.length < 1) {
          $('#reg_message').html('You must enter a username');  
          
        } else if (user_pass.length < 1) {
          $('#reg_message').html('You must enter a password');  
        } else {
          $.post("/wp-content/themes/karl-george/wp-ffwd-login.php",{action: 'register', user_email: user_email, user_pass: user_pass, user_login: user_login},
          function(data){
            if (data.success == 'true') {
              window.location = '/';
            } else {
              $('#ffwd_login_error').html(data.error);        
            }
          },'json');
        }
        return false;
      }
    });    
    
    
    $('#ffwd_submit').live('click', function() {
      
      var user_email = $('#ffwd_reg_user_email').val();
      var user_login = user_email;
      
      $.post("/wp-content/themes/karl-george/wp-ffwd-register-start.php",{action: 'register', user_email: user_email, user_login: user_login},
      function(data){
        if (data.success == 'true') {
          $('#signupForm').submit();
        } else {
          $('#reg_message').html(data.error);        
        }
      },'json');
    });
    
    $('#ffwd_register').live('click', function() {
      
      var user_email         = $('#user_email').val();
      var user_login         = $('#user_login').val();
      var user_pass          = $('#user_pass').val();
      var user_first_name    = $('#user_first_name').val();
      var user_surname       = $('#user_surname').val();
      var user_hear          = $('#user_hear').val();
      var user_blog          = 'No';
      var user_tel           = $('#user_tel').val();
      var service_speaking   = 'No';
      var service_governance = 'No';
      var service_leadership = 'No';
      var service_resources  = 'No';
      var error              = new Array();
      var i                  = 0;
      
      if (user_pass.length < 1) {
        error[i] = 'The Password field cannot be left blank.<br />';
        i++;
      }      
      
      if (user_pass.length < 8) {
        error[i] = 'The Password field must contain at least 8 characters.<br />';
        i++;
      }          
      
      if (user_first_name.length < 1) {
        error[i] = 'The First Name field cannot be left blank.<br />';
        i++;
      }
      
      if (user_surname.length < 1) {
        error[i] = 'The Surname field cannot be left blank.<br />';
        i++;
      }
      
      if ($('#user_blog').attr('checked')) {
        user_blog = 'Yes';
      }      
      
      if ($('#service_speaking').attr('checked')) {
        service_speaking = 'Yes';
      }
      if ($('#service_governance').attr('checked')) {
        service_governance = 'Yes';
      }
      if ($('#service_leadership').attr('checked')) {
        service_leadership = 'Yes';
      }
      if ($('#service_resources').attr('checked')) {
        service_resources = 'Yes';
      }      
      
      if (i) {
        
        $('#ffwd_register_error').html('');
        
        for (c = 0;c < i;c++) {
          $('#ffwd_register_error').append(error[c]);
        }
      } else {

        $('#ffwd_register_error').html('');

        $.post("/wp-content/themes/karl-george/wp-ffwd-register.php",{
                                           action: 'register', 
                                           user_email: user_email, 
                                           user_login: user_login, 
                                           user_pass: user_pass,
                                           user_first_name: user_first_name,
                                           user_surname: user_surname,
                                           user_hear: user_hear,
                                           user_blog: user_blog,
                                           user_tel: user_tel,
                                           service_speaking: service_speaking,
                                           service_governance: service_governance,
                                           service_leadership: service_leadership,
                                           service_resources: service_resources},
        function(data){
          if (data.success == 'true') {
            $('#ffwd_register_form').html(data.message);
          } else {
            $('#ffwd_register_error').html(data.error);        
          }
        },'json');
      }

    });    
    
    $('#ffwd_redeem_password').live('click', function() {
      
      var user_email = $('#ffwd_redeem_email').val();
      
      $.post("/wp-content/themes/karl-george/wp-ffwd-redeem.php",{action: 'redeem', user_email: user_email},
      function(data){
        if (data.success == 'true') {
          $('#ffwd_redeem').html(data.message);
        } else {
          $('#ffwd_redeem').html(data.error);        
        }
      },'json');
    });    
    


    if ($('#videoContainer').length) {
      
      var videoFirst = '';

      videoFirst = $('.thumbs ul li a:first-child').attr('rel');      
      
      var videos = videoFirst.split(':');
      var title  = videos[0];
      //var width  = videos[1];
      //var height = videos[2];
      var width  = 560;
      var height = 315;      
      var url    = '';

      if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
        url = '<iframe src="http://player.vimeo.com/video/' + title + '?title=0&amp;byline=0&amp;portrait=0" width="' + width + '" height="' + height + '" frameborder="0"></iframe>';                
      } else {
        url = '<object width="' + width + '" height="' + height + '"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + title + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + title + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + width + '" height="' + height + '"></embed></object>';                  
      }
      
      $('#videoContainer').html(url);  
    }
    
    // Video gallery                       
    $('.thumbs ul li a').each(function() {
      
        $('.thumbs ul li:first-child').addClass('selected');
        
        $(this).click(function(){
            var video = $(this).attr('rel');  
            
            var videos = video.split(':');
            var title  = videos[0];
            //var width  = videos[1];
            //var height = videos[2];
            var width  = 560;
            var height = 315;
            var url    = '';

            if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
              url = '<iframe src="http://player.vimeo.com/video/' + title + '?title=0&amp;byline=0&amp;portrait=0" width="' + width + '" height="' + height + '" frameborder="0"></iframe>';                
            } else {
              url = '<object width="' + width + '" height="' + height + '"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + title + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + title + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + width + '" height="' + height + '"></embed></object>';                  
            }
            $('#videoContainer').html(url);
            //console.log(video);   
            $('.thumbs ul li').removeClass('selected');
            $(this).parent('li').addClass('selected');
            return false;
        });
              
		$('#vimeo-1, #vimeo-4').click(function(){
			$('.videoGal p span').css('background-position', '0 100%');
		});	
		$('#vimeo-2, #vimeo-5').click(function(){
			$('.videoGal p span').css('background-position', '121px 100%');
		});	
		$('#vimeo-3, #vimeo-6').click(function(){
			$('.videoGal p span').css('background-position', '243px 100%');
		});	        
        
    });
    
    $('.orderLink').mousedown(function(){
      $(this).addClass('orderLinkPressed');
    }).mouseup(function(){
      $(this).removeClass('orderLinkPressed');
    });

    $('.formPan button').mousedown(function(){
      $(this).addClass('pressed');
    }).mouseup(function(){
      $(this).removeClass('pressed');
    });
    
});

// Drop Down
$(document).ready(function(){

$('.topHeader ul li').hover(
function () {
    $(this).addClass('active');
    $(this).children('ul').fadeIn('fast');
},
function () {
    $(this).removeClass('active');
    $(this).children('ul').fadeOut();
}
);
});

// footer Drop Down
$(document).ready(function(){

$('.footer ul li').hover(
function () {
    $(this).addClass('active');
    $(this).children('ul').fadeIn('fast');
},
function () {
    $(this).removeClass('active');
    $(this).children('ul').fadeOut();
}
);
});

// Other Script
$(document).ready(function(){
    $('.mainMenu ul li:first').css('background','none');
    $('.footer ul li ul li:first').css('background','none');
    $('.footer ul li:first').css('background','none');
    $('blockquote p:first').addClass("quote");
})

