var baseUrl = $('base').attr('href');
var activePane;
var activeUserMeta;     
var times = new Array();   

function displayDropdown(id, time) {
    $(id).slideToggle(time);
} 

function togglePane(div) {
    $(div).slideToggle(800);
    if(activePane != null && activePane != div) {
        $(activePane).slideToggle(800);
    }
    activePane = div;
}

function sentCallback(name, email, phone, enquiry, times) {    
  var dataString = 'customer-name='+ name + '&customer-email=' + email + '&customer-number=' + phone + '&enquiry=' + enquiry + '&early-morning=' + times[0] + '&late-morning=' + times[1] + '&lunchtime=' + times[2] + '&early-afternoon=' + times[3] + '&late-afternoon=' + times[4] + '&early-evening=' + times[5] ;
  $.ajax({
    type: "POST",
    url: baseUrl + 'callback/callback.php',
    data: dataString,
    success: function() {
        $('.success').fadeIn(1000);
        $(".success").animate({
            opacity: 'hide',
            height: 'hide'        
        }, 4000);   
    }
  });
  return false;
}

function changeAction(linkClass) {
    if(linkClass == 'client-login') {
        $('form[name=login]').attr('action', 'client-login'); 
    } else if(linkClass == 'web-mail') {
        $('form[name=login]').attr('action', 'webmail'); 
    }
}


$(document).ready(function() {
    $('#web-more').hide();
    $('#branding-more').hide();
    $('#motion-more').hide();
    $('#print-more').hide();
    $('.contact-dropdown').hide();
    $('.error').hide();
    $('.success').hide();
    $('.user-meta form').hide();
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
if ($.browser.msie && $.browser.version.substr(0,1)<7) {

} else {
	$(document).pngFix(); 	
    
    $('a.show-content').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        positionRight: true
    });	
}	

    $('#updates a').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        positionRight: true
    });
	
    $('a.toggleSiteMap').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        positionRight: true
    });	
	
	
    
    $('#home-1 a.show-content').click(function() {
        if(activePane != '#web-more') {
            togglePane('#web-more');
        }
    }); 
    
    $('#home-2 a.show-content').click(function() {
        if(activePane != '#branding-more') {
            togglePane('#branding-more');
        }
    }); 
    
    $('#home-3 a.show-content').click(function() {
        if(activePane != '#motion-more') {
            togglePane('#motion-more');
        }
    }); 
    
    $('#home-4 a.show-content').click(function() {
        if(activePane != '#print-more') {
            togglePane('#print-more');
        }
    });   
    
    $('.initiate-dropdown').click(function() {
        displayDropdown('.contact-dropdown', 400);        
    }); 
	
    $('.toggleSiteMap').click(function() {
        displayDropdown('#sitemap-list', 400);     
		displayDropdown('.toggleSiteMap', 400);   
    }); 	
	
    
    $('.user-meta a:not(.initiate-dropdown)||a:not(.web-mail)').click(function() {
            if($(this).attr('class') == activeUserMeta) {
                $('.user-meta form').slideUp(400); 
                activeUserMeta = null;
            }  else if (activeUserMeta != null && $(this).attr('class') != activeUserMeta) {
                $('.user-meta form').slideToggle(400); 
                $('.user-meta form').slideToggle(400); 
                activeUserMeta = $(this).attr('class');  
                changeAction($(this).attr('class'));
            } else {
                $('.user-meta form').slideToggle(400); 
                activeUserMeta = $(this).attr('class');  
                changeAction($(this).attr('class')); 
            }
            
    });
    
    $('.button[name=send-callback]').click(function() {
        $('.error').hide();
        
        var name = $('input[name=customer-name]').val();
        if(name == '') {
            $('label#name-error').show();
            $('input[name=customer-name]').focus();
            return false;
        }
        
        var email = $('input[name=customer-email]').val();
        if(email == '') {
            $('label#email-error').show();
            $('input[name=customer-email]').focus();
            return false;
        }
        
        var phone = $('input[name=customer-number]').val();
        if(phone == '') {
            $('label#number-error').show();
            $('input[name=customer-number]').focus();
            return false;
        } 
        var enquiry = $('textarea[name=enquiry]').val();
        
        times[0] = $('input[name=early-morning]').attr('checked');
        times[1] = $('input[name=late-morning]').attr('checked');
        times[2] = $('input[name=lunchtime]').attr('checked');
        times[3] = $('input[name=early-afternoon]').attr('checked');
        times[4] = $('input[name=late-afternoon]').attr('checked');
        times[5] = $('input[name=early-evening]').attr('checked');
        displayDropdown('form[name=contact]', 400);
		// do post and redirect instead of ajax call
        //sentCallback(name, email, phone, enquiry, times);  
        return true;
    }); 
       
    $('.show-content span').mouseenter(function() {  
        var blockItem = '.show-content span img:not(.show-content #' + $(this).attr('id') + ' img )';
        $(blockItem).stop().animate({ opacity: 0.0 }, 300);    
    });  
    
    $('.show-content').mouseout(function() {
        $('.show-content span img').stop().animate({ opacity: 1.0 }, 300);      
    });         
});




