/* Author: Greg Lane, fusionbureau */

/* function for handling footer menu */

$(document).ready(function(){

$(".footnav").click(function(e) {
    
        $('.footnav').each(function() {
            $(this).css("color","#ffffff");
            $(this).css("background-color","#000000");
        });
        $(this).css("color","black");
        $(this).css("background-color","yellow");
        $('#slidedown-padding > section').each(function() {
            $(this).hide();
        });
        
        /* find out if slidedown is already open */
        var visstate = $("#footer-slidedown").is(":visible");
        
        $("#footer-slidedown").show();
        
        var newloc = $(this).attr('href');
        $(newloc).show();

        if(!visstate){
        var newheight = $(document).height();
        $('html, body').animate({scrollTop:newheight}, 4000);
        }
        e.preventDefault();
    });

$(".catnav").click(function(e) {
    
        $('.catnav').siblings().each(function() {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
        
        /* project images */       
        $('#project-pic > div').each(function() {
            $(this).hide();
        });
        var newimg = "#" + $(this).attr('id') + "-images";
        $(newimg).fadeIn('fast');
        $(newimg + " > div > div").show();

        $(".summary-wrapper").hide();

        var newsum = "#" + $(this).attr('id') + "-summary";

        /* project summary */
        $(newsum).fadeIn();

        e.preventDefault();
    });

$(".arrow-next").click(function(e) {  
/*    $(this).parent().hide("slow");*/
    $(this).parent().parent().animate({left:'-=928px'},'slow');
    var newsumtxt = $(this).attr('name');
    
    /* project summary */     
    var sumparentid = "#" + $(newsumtxt).parent().attr('id');
    
    $(sumparentid).children().each(function() {
            $(this).hide();
    });
    $(newsumtxt).fadeIn('fast'); 
    e.preventDefault();
    });


$(".arrow-prev").click(function(e) {
        
$(this).parent().parent().animate({left:'+=928px'},'slow');
var newsumtxt = $(this).attr('name');

/* project summary */ 
var sumparentid = "#" + $(newsumtxt).parent().attr('id');

$(sumparentid).children().each(function() {
        $(this).hide();
});

$(newsumtxt).fadeIn('fast');    

e.preventDefault();
});

/* Contact form AJAX */
  
$("#submit_contact").click(function(e) {
$(this).attr('disabled', 'disabled');        
var email = $("#senderemail").val();
var message = $("#message").val();
var dataString = 'ajax=true&email=' + escape(email) + '&message=' + escape(message);

if(email=='')
{
    alert("Please enter a valid email address.");
}
else
{
$.ajax({
type: "GET",
url: "/front/helpers/contact.php",
contentType: "charset=utf-8",
data: dataString,
success: function(){
$('#contactfrm').hide();    
$('#contact-thanks').fadeIn('slow');
}
});
}
e.preventDefault();
});  
  
  
/* Newsletter sign-up AJAX */

$("#submit_newsletter").click(function(e) {
var email = $("#newsletter_email").val();
var newslang = $("#newsletter_lang").val();
var dataString = 'ajax=true&email='+ escape(email) + '&newslang=' + newslang;

/*alert(dataString);*/
$.ajax({
        url: 'http://www.fusionbureau.com/front/helpers/newsletter.php',
        data: dataString,
        success: function(msg) {
                $('#response').html(msg);
                $('#newsletter_form').hide();    
                $('#newsletter_success').fadeIn('slow');                           
        }
});
    
e.preventDefault();

}); 
   
$(".service-box").click(function() {  
        var service = $(this).children('a').attr("href");
        document.location.href=service;
});

    
$(".proj-nav").click(function(e) {
 
$(this).addClass('activelink');       
$(this).siblings().removeClass('activelink');

var showcat = $(this).attr("name").substring(1);
$(".project-block").hide();

if(showcat == "all"){
  $(".project-block").fadeIn("slow");
} else {
 $(".project-block").each(function() {
    var thisblock = $(this).attr("name");
    if(thisblock == showcat)
    {$(this).fadeIn("slow");}
});
}
e.preventDefault();
        
});
    
$(".project-block").hover(
  function () {
    $(this).children("div").fadeIn("fast");
  },
  function () {
    $(this).children("div").fadeOut("fast");
  }
); 
    
});

/* slow rotator for black box. */

function slideSwitch() {
                /*alert("boo");*/
                firstnotice = $(".notice").first();
                myactive = $('.notice.active');
		mynext = myactive.next(".notice");

                myactive.fadeOut(1000,function(){
                        if(mynext.length == 0){
                                mynext = firstnotice;
                        }
//alert(mynext.length);
                        mynext.fadeIn(1250); 
                        myactive.removeClass('active');
                        mynext.addClass('active');
/* links with slide panel */
			$("#notice-nav a").each(function() {
				var thislink = $(this).attr("href");
				var newlink = mynext.attr("id");
				var oldlink = myactive.attr("id");
				//alert(thislink);
				if(thislink == newlink){
					$(this).removeClass("inactivenotice");
					$(this).addClass("activenotice");					 
				}
				if(thislink == oldlink){
					$(this).removeClass("activenotice");
					$(this).addClass("inactivenotice");					 
				}
			});

                });
        }
        
$(function() {
        setInterval( "slideSwitch()", 10000 );
});

$("#notice-nav a").click(function(e) {

$(this).siblings().removeClass("activenotice");
$(this).siblings().addClass("inactivenotice");
$(this).removeClass("inactivenotice");
$(this).addClass("activenotice");

var noticebox = "#" + $(this).attr("href");
        
$(".notice").removeClass('active');
$(".notice").hide();
$(noticebox).fadeIn(1250);
$(noticebox).addClass('active');

e.preventDefault();
});


$(function() {
    $('a[rel*=external]').click( function() {
        window.open(this.href);
        return false;
    });
});

$(function() {
   $('.gallery a').lightBox({
        fixedNavigation:true,
	overlayOpacity: 0.6,
	imageLoading: '/front/themes/fb/img/loading.gif',
	imageBtnClose: '/front/themes/fb/img/close.gif',
	imageBtnPrev: '/front/themes/fb/img/arrow_left.png',
	imageBtnNext: '/front/themes/fb/img/arrow_right.png',
	containerResizeSpeed: 350
   });
});

$(function() {
if($('.gallery').length > 0){        
$('.mainimage').click(function(e) {
        $('#galleryfirst').trigger('click');     
    e.preventDefault();
});
}else{
   $('.mainimage').lightBox({
        fixedNavigation:true,
	overlayOpacity: 0.6,
	imageLoading: '/front/themes/fb/img/loading.gif',
	imageBtnClose: '/front/themes/fb/img/close.gif',
	imageBtnPrev: '/front/themes/fb/img/arrow_left.png',
	imageBtnNext: '/front/themes/fb/img/arrow_right.png',
	containerResizeSpeed: 350
   });
}
});

/* Google+ code */

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();




















