
//cufon


if ($.browser.msie && $.browser.version.substr(0,1)<7) { }
else { Cufon.replace('h1,h2,h3,#error_search .title',{ hover: true }); }


// host

var hostname =  "http://"+top.location.host+"/";


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//declair variables	
var profileexpanded = 0;
var backclicked = 0;
var curid = 0;
var position2 = 0;
var peopleheight = 0;
var nameleft = 0;
var loaded = 0;
var infoheight = 0;
var textheight = 0;
var clientid = 0;
var expanded = 0;
var searched = 0;
var titlewidth = 0;
var changed = 0;				
var clienthover = 0;
var currentclient = 0;
var testheight = 0;
var newheight = 0;
var searchtext = 0;
var linktitle = 0;
var linkurl = 0;
var position = 0;
var clienttitle = 0;
var currentid = 0;
var linkcontent = 0;
var showheight = 0;
var minheight = 0;
var h2content = 0;
var overlay = 0;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//FUNCTIONS

//button click

function buttonclick(url) {
	
window.location.href = url;	
	
}

//testimonial next
function testimonialClick() {
	
//get currentid	


testheight = $('#testimonial .testimonial').height();
$('#testimonial').height(testheight);
	
 $('#testimonial .testimonial').fadeOut(200,function() {
													 
currentid = $('#testimonial .author').attr('name');													 

 $.ajax({  
  type: "GET",  
  url: hostname+'/resources/ajax/test.php?number='+currentid+'&random='+Math.random()*9999,  
  dataType: "html",
  data: $("input:first"),  
  success: function(data) { 
  
  $('#testimonial .testimonial').html(data);
  $('#testimonial .testimonial').fadeIn(200);	
  
newheight = $('#testimonial .testimonial').height();
$('#testimonial').animate({height: newheight},200); 
  

  
  }  
});
 });	

}




//get hash
function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}


//search expand
function searchExpand() {
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
	document.getElementById("cover").style.display = "none";
	}
	else { document.getElementById("cover").style.display = "block"; }
	
	if (searched == 1) {
	$('#search_results').fadeIn(300);	
	}
	
	document.getElementById('s').style.display = "block";
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	$('#header ul').fadeOut(0) ;
	}
	
	else { $('#header ul').fadeOut(200); }
	$('#search_inner').animate({width: '252px'},300, function() {
	document.getElementById('s').focus();														  
	});
	$('#search_button').animate({opacity: '1'},70).css('cursor','auto');
	expanded = 1;
}

//search collapse
function searchCollapse() {
	if ($.browser.msie && $.browser.version.substr(0,1)<7) { }
	else { $('#header ul').fadeIn(200); }
	$('#search_results').fadeOut(300);
	$('#search_inner').animate({width: '13px'},300, function() {
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		document.getElementById("cover").style.display = "block";
		$('#header ul').fadeIn(0);
	}
	else { document.getElementById("cover").style.display = "none"; }
	
	document.getElementById('s').style.display = "none";
	});
	$('#search_button').animate({opacity: '1'},70).css('cursor','auto');
	expanded = 0;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function(){	

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// feedback tab

if ($.browser.msie && $.browser.version.substr(0,1)<7) {}

else if ($.cookie('feedback')) {
	
	$('#feedback').fadeIn(0);
	
}

else {

	$('#feedback').delay(1000).fadeIn(1000,function(){
												
		$.cookie('feedback', '1', { expires: 1 });											
												
	});

}

$('#feedback').hover(function(){
							  
	$(this).animate({left: 0},100);

},function(){
	
	$(this).animate({left: -8},100);

});

$('#feedback').click(function(){
							  
	if (overlay != 1) {						  
	
		$('#overlay .inner').html('<span class="close">close</span><iframe src="https://spreadsheets.google.com/embeddedform?formkey=dEktWG9sbnlIN3RPeExmZ0Q2OHZJVFE6MQ" width="720" height="640" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>');
	
	}
	
	$('#overlay').fadeIn(0);
	
	overlay = 1;
	
});	

$('#overlay .inner .close').live('click',function() {
										   
	$('#overlay').fadeOut(0);								   
										   
});




						   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//IE6 fixes
if ($.browser.msie && $.browser.version.substr(0,1)<7) {

//search related
document.getElementById("cover").style.backgroundImage = "url('"+hostname+"resources/images/button_right_coverie.gif')";
document.getElementById("search_inner").style.backgroundImage = "url('"+hostname+"resources/images/searchie.png')";
$('#search_results .top').height(0);
document.getElementById("cover").style.display = "block";
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
//IE 6 + 7 fixes
if ($.browser.msie && $.browser.version.substr(0,1)<8) { 

//fetch people module height and set it				
peopleheight = $('#profile_info').parent().parent().height();
$('#profile_info').parent().parent().height((peopleheight));

$('#s').css('top','3px');

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
//IE 7 fixes
if ($.browser.msie && $.browser.version.substr(0,1) == 7) {


$('h3 img').css('margin-top','2px');

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//when hover over search
$("#search_button").hover(function() {
	if (expanded === 0) {								   
		$(this).stop().animate({"opacity": "0.7"}, 70).css('cursor','pointer');
	}
},
function() {
	if (expanded === 0) {
		$(this).stop().animate({"opacity": "1"}, 70);
	}
});

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//when click outside search - collapse
$('html').click(function() {
	searchCollapse();
});
//excluded divs:
$('#search_button').click(function(event){
	event.stopPropagation();
});
$('#search_results').click(function(event){
	event.stopPropagation();
});
 
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 //when search submitted
$('#searchform').submit(function() {
	
searchtext = $("input:first").val();
searchtext = $.trim(searchtext);

								 
  $.ajax({  
  type: "GET",  
  url: hostname+'?s='+searchtext,  
  dataType: "html",  
  success: function(data) { 
  $('#search_results').fadeIn(100);
  $('#search_results .mid').html(data); 
  searched = 1;
  }  
});  
  return false;
});
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//button replace

$('.button_link').each(function() {							
linktitle = $(this).html();	
linkurl = $(this)[0].href;
$(this).parent().replaceWith('<div class="button" onclick="buttonclick(\''+linkurl+'\')"><div class="left"></div><div class="center">'+linktitle+'</div><div class="right"></div></div>');														
});


//create testimonal next replace

$('.testimonial_next').each(function() {							
$(this).replaceWith('<div class="button more" onClick="testimonialClick()"><div class="left"></div><div class="center">Next</div><div class="right"></div></div>');														
});


//create search button

$('#search_button').each(function() {							
$(this).fadeIn(0);
});


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//button hover 
$(".button").hover(function() {
		if (backclicked === 0){					
		$(this).stop().animate({"opacity": "0.7"}, 70).css('cursor','pointer');
		}
},
function() {
	if (backclicked === 0){	
	    $(this).stop().animate({"opacity": "1"}, 70);
	}
});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





	
//when click on profile face	
$(".face").click(function() {	
						  
if (profileexpanded === 0) {	

profileexpanded = 1;

//fetch people module height and set it				
peopleheight = $('#profile_info').parent().parent().height();
$('#profile_info').parent().parent().height((peopleheight));


//loop through each .face and set top/left positioning
$(".face").each(function(index) {
						 
var position = $(this).position();
this.style.left = position.left+'px';
this.style.top = position.top+'px';

});		

//set each .face to absolute
$(".face").css('position','absolute');

//loading
position = $('#profile_info').parent().parent().position();
$('#loading').css('top',position.top+70);
$('#loading').css('left',196);
loaded = 0;
$('#loading').delay(300).fadeOut(0, function() {
if (loaded === 0) {
$('#loading').fadeIn(200);	
}
});

//ajax
$.ajax({  
type: "GET",  
url: "resources/ajax/profile.php?id="+$(this).attr('id'), 
dataType: "HTML",
success: function(data) {
loaded = 1;
$('#loading').fadeOut(200);	
$('#profile_info').html(data);
infoheight = $('#profile_info').height();
textheight = $('#profile_info').parent().parent().children('.people').height();
if (infoheight > textheight) {
$('#profile_info').parent().parent().animate({height: (infoheight+80)},300);
}
$('#profile_info').fadeIn(200);
$('#profile_back').fadeIn(200);	

}  
});	

//begin animations
$(this).siblings('.face').fadeOut(300);
$(this).children('.border').fadeOut(0);
$(this).children('img').animate({height: 105, width: 90},300);
$(this).animate({left: 0, top: 0, height: 105, width: 90},300,function(){


	

																	   
});

		
//set variables for back function
curid= $(this).attr('id');
position2 = $(this).position();

//fade out and border
$('#name_'+curid).fadeOut(0);

}
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//when click back
$('#profile_back').click( function() {			
if (backclicked === 0){	
backclicked = 1;
$('#profile_info').fadeOut(300);
 $(this).fadeOut(300);
 $('#profile_info').parent().parent().animate({height: peopleheight},300);
$('#'+curid).children('img').animate({height: 70, width: 60},300);
$('#'+curid).animate({left: position2.left, top: position2.top, height: 70, width: 60},300, function() { 
profileexpanded = 0; 
backclicked = 0;
$('.face').fadeIn(200);
});
}
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//when hover over profile face
$(".face").hover(function() {
if (profileexpanded === 0) {
//fetch id	
var currentId = $(this).attr('id');	
//Calculate and set position 
var position = $(this).position();
var namew = $('#name_'+currentId).width();
if (namew > 60) { 
nameleft = (position.left - ((namew - 60))/2); 
} 
else { 
nameleft = (position.left + ((60 - namew)/2)); 
}
$('#name_'+currentId).css('position','absolute');
$('#name_'+currentId).css('left', nameleft+'px');
//if IE6 remove curl						   
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
$('#name_'+currentId).css('backgroundImage', 'url(none)');	
$('#name_'+currentId).css('top', (position.top + 7)+'px');
}
else {
$('#name_'+currentId).css('top', (position.top)+'px');	
}
//fade in name and border
$('#name_'+currentId).fadeIn(0);	
$(this).children('.border').fadeIn(0);
$(this).css('cursor','pointer');
}

}, function() {	

var currentId = $(this).attr('id');	
$('#name_'+currentId).fadeOut(0);	
$(this).children('.border').fadeOut(0);
$(this).css('cursor','auto');

});


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




if ($.browser.msie && $.browser.version.substr(0,1) < 7) { } 

else {

//when hover over client
$('.client').hover(function() {
							

currentclient = $('#client_column .title').html();
currentclient = $('&lt;div&gt;' + currentclient + '&lt;/div&gt;').text();							
							
clienttitle =  $(this).children('.client_right').children('.title').children('.clientname').html();
							
if (clienttitle != currentclient) {
		
clienthover = 1;	
							
//if IE dont fade
if ($.browser.msie) {
$(this).children('.info').css('display','inline-block');
}
else {
$(this).children('.info').stop().fadeTo(150,1);	
}
//get height of info and animate open
infoheight = $(this).children('.info').height();
if ($.browser.msie && $.browser.version.substr(0,1) == 7) {
infoheight = infoheight+10;
}
$(this).stop().animate({height: 85+infoheight},150);
$(this).css('cursor','pointer');							
}
}, function() {
//if IE6 dont fade	
if ($.browser.msie) {
$(this).children('.info').stop().delay(150).css('display','none');
}
else {
$(this).children('.info').fadeOut(150);	
}
//animate close
$(this).stop().animate({height: 85},150);

});	

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//when click on client

$('.client').click(function() {


currentclient = $('#client_column .title').html();
currentclient = $('&lt;div&gt;' + currentclient + '&lt;/div&gt;').text();		
		
clienttitle =  $(this).children('.client_right').children('.title').children('.clientname').html();

if (clienttitle != currentclient) {
							
var href = $(this).children('.client_right').children('.title').children('.clientname').children('a').attr('href');
window.location.href = href;

}

});

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//when client page loads find current client and expand box



$('.client').each(function(){						   

currentclient = $('#client_column .title').html();
currentclient = $('&lt;div&gt;' + currentclient + '&lt;/div&gt;').text();						   
												  
clienttitle =  $(this).children('.client_right').children('.title').children('.clientname').html();

if (clienttitle == currentclient) {

$(this).children().fadeTo(0,0.3);

}

});


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// what we do sublist collapse and rollover

// hide on load

$('.cattitle ul').each(function(){
	
	if ($(this).children('.selected').length > 0) { } else {
	
		$(this).fadeOut(0);
		
	}
		
});

// rollover expand

$('.cattitle').hover(function(){
							  
	if ($(this).children('ul').children('.selected').length > 0) {} else {
	
		$(this).children('ul').slideDown(100);
		
	}						  
							  
						  
							  
},function(){
	
	if ($(this).children('ul').children('.selected').length > 0) {} else {
	
		$(this).children('ul').slideUp(100);
		
	}				
					
});


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



$("#twitter_div").getTwitter({
					userName: "addchillisauce",
					numTweets: 1,
					loaderText: "<div style=\"width:140px;text-align:center;padding:10px\">Loading</div>",
					slideIn: false,
					slideDuration: 750,
					showHeading: false,
					headingText: "Latest Tweets",
					showProfileLink: false,
					showTimestamp: true
				});

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//load map

$('#googlemap').replaceWith('<iframe width="250" height="250" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=211345961899148463364.000485c4ec5d053018a23&amp;ll=51.516381,-0.137093&amp;spn=0.001649,0.002671&amp;z=17&amp;output=embed"></iframe>');


/////////END READY//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});


//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
/////////////TWITTER//////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////

(function($) {
	/*
		jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	$.fn.getTwitter = function(options) {

		$.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 5,
			loaderText: "Loading tweets...",
			slideIn: true,
			slideDuration: 750,
			showHeading: true,
			headingText: "Latest Tweets",
			showProfileLink: true,
			showTimestamp: true
		};

		var o = $.extend({}, $.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = $(this);

			// hide container element, remove alternative content, and add class
			c.hide().empty().addClass("twitted");

			// add heading to container element
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}

			// add twitter list to container element
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = $("#twitter_update_list");

			// hide twitter list
			tl.hide();

			// add preLoader to container element
			var preLoaderHTML = $("<p class=\"preLoader\">"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			// add Twitter profile link to container element
			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			// show container element
			c.show();

			$.getScript("http://twitter.com/javascripts/blogger.js");
			$.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				// remove preLoader from container element
				$(preLoaderHTML).remove();

				// remove timestamp and move to title of list item
				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = $(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						$(this).attr("title", timestamp);
					});
				}

				// show twitter list
				if (o.slideIn) {
					// a fix for the jQuery slide effect
					// Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
					var tlHeight = tl.data("originalHeight");

					// get the original height
					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				// add unique class to first list item
				tl.find("li:first").addClass("firstTweet");

				// add unique class to last list item
				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);

//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////
//////////////////////////////////

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};




