/* global actions */

$('body').removeClass('noscript').addClass('jscript');

$('html').removeAttr('class');

$(function(){

$('a.active').click(function(e){e.preventDefault();});

});


/* global variables */

animSpeed = 500;

var animFX = 'easeInOutCubic';

//  Circ   Cubic  Quart   Quint    Sine    Elastic    Back    Bounce    Expo
/* #main */

// #main

$('#main ul.navi a').click(function(){

if ( !$(this).hasClass('active') ) {$('#main ul.navi a').removeClass('active');}

var targetVar = $(this).attr('href'); // Get anchor from link 

if ( !$(targetVar).is(':animated') && !$(targetVar).hasClass('active') ) { // Check if targetVar is not animated AND does not have class active

var fluxClass = $('.active').css('z-index'); // get z-index value from .active class...

fluxClass++; // ...and add 1

$(targetVar)						

			.css({'z-index':fluxClass,'opacity':0})    	  // set inline style of targetVar to fluxClass value 

		  .animate({'opacity':1},animSpeed, function(){//.fadeIn(animSpeed, function(){ 	// fadeIn targetVar first and then perform function
				
				$('#main div.main').removeClass('active');
				
				$(targetVar).removeAttr('style')       // remove inline style...

							.addClass('active');});  // and apply .active class
							
$(this).addClass('active');

}

if ( targetVar != '#header' ) {return false;} // Applies return false on all except the #header link

});

/* #clients */

// BEGIN Display handle if total width of content exceeds width of parent

$('#clients_container:last-child').after('<div id="scrollbar"><div class="line"></div><div class="handle"></div></div>');

var qtyVar = $('#clients_container').children().length; // gets the total amount of child div elements

var widthVar = $('#clients_container').children().outerWidth( true ); // gets the total width of an individual child element

var containerVar = (qtyVar * widthVar); // finds the combined total width of all child div elements

$('#clients_container').css({'width':containerVar + 'px'}); // sets the width of the parent container

var clientsVar = $('#clients').outerWidth( true ); // gets width of #clients

if ( clientsVar > containerVar ) { $('#scrollbar').hide(); } // if width of #clients_container is greater than width of #clients, display #scrollbar

// END

// BEGIN scrollbar slider

/**/$('#scrollbar .handle').css({'width':clientsVar / qtyVar + 'px'});/**/ // sets width of handleVar proportional to the number of .clients divs

var lineWidth = parseInt( $('#scrollbar .line').outerWidth ( true ) );// get width of slider line

var handleWidth = parseInt( $('#scrollbar .handle').outerWidth( true ) );// get width of handle

var maxWidth = lineWidth - handleWidth; // subtract width of handle from slider line

var incrementVar = ( containerVar - maxWidth - handleWidth ) / maxWidth; // this value will be the increments that the container will move

$('#scrollbar .handle').mousedown(function(e){

$(this).addClass('active');

$('body').disableTextSelect();


var originPos = e.pageX; // get current x pos of mouse

var handlePos = parseInt( $('#scrollbar .handle').css('margin-left') ); // get current position of .handle

$('html').mousemove(function(e){

if ( $('#scrollbar .handle').hasClass('active') ) { 

var newPos = e.pageX; // track new x pos of mouse

 

offsetPos = newPos - originPos + handlePos; // find difference between original x pos and new x pos and add handlePos

slideVar = offsetPos * incrementVar;

if ( offsetPos < -1 || offsetPos > maxWidth ) {return;} // stop if the offsetPos is less than -1, or more than the width of .line 

else { $('#scrollbar .handle').css({'marginLeft':offsetPos + 'px'});       // move .handle by offsetPos value 

       $('#clients_container').stop().animate({'marginLeft':'-' + slideVar + 'px'}, animSpeed)} // move #clients_container by slideVar value

} else {return;}

$('html').mouseup(function(){ $('#scrollbar .handle').removeClass('active'); $('body').enableTextSelect();});

}); // CLOSE mousemove

}); // CLOSE mousedown

// END



/* #services */

var servicesVar = $('#services').outerWidth ( true ); // get width of #services

var handleVar = $('#services .handle').outerWidth( true ); // get width of .handle


$('#services div.services').each(function(){  // set initial position of each div.services

var indexVar = $(this).index();

if ( indexVar == 0 ) {return} // first div.services does not need to be offset, so ignore everything after this

var offsetVar = handleVar * indexVar; // get handle offset value of handleVar

var positionVar = servicesVar - offsetVar; // subtract offsetVar from width of #services

$(this).css({'left':'-' + positionVar + 'px', 'z-index': positionVar}); // set left position of this div

}); // END div.services position


$('#services .handle').click(function(){

var positionVar = $(this).parent().css('left');

if ( $(this).hasClass('active') ) {

var indexVar = $(this).parent().index();

if ( indexVar == 0 ) {return} // first div.services does not need to be offset, so ignore everything after this

var offsetVar = handleVar * indexVar; // get handle offset value of handleVar

var positionVar = servicesVar - offsetVar; // subtract offsetVar from width of #services

$(this).removeClass('active').parent().animate({'left':'-' + positionVar + 'px'}, animSpeed, animFX);

}

else

{ 

$(this).addClass('active').parent().animate({'left':'0px'}, animSpeed, animFX); 

}

});

/* #comprehensive_marketing */


// #form_sector

$(document).ready(function(){

$('#form_sector').each(function(){		   

var sector = $(this).val().toLowerCase().replace(' ','_');;
$('#map_sectors img').removeClass('active');
$('#map_sectors img[src="images/map_' + sector + '.png"]').fadeIn('fast').addClass('active');
$('#map_sectors img[class*="sector"]').hide();
$('#map_sectors img.active').show();

});

});

$('#form_sector').change(function(){ //BEGIN sector input change TO map sector

								  

sector = $(this).val().toLowerCase().replace(' ','_');

$('#map_sectors img').removeClass('active');

$('#map_sectors img[src="images/map_' + sector + '.png"]').fadeIn('fast').addClass('active');

$('#map_sectors img[class*="sector"]').hide();

$('#map_sectors img.active').show();

});//END sector input change TO map sector

// #map_sectors

$('#Map area').each(function(){ // BEGIN populate #map_sectors
							 
sector = $(this).attr('alt').toLowerCase().replace(' ','_');

$(this).attr('id', 'sector_' + sector);

$('#map_sectors').append('<img src="images/map_' + sector + '.png" alt="" usemap="#Map" class="sector_' + sector + '" />');

$('#map_sectors img[class*="sector"]').hide();

}); 

// END populate #map_sectors

$('#Map area').hover(function(){ // BEGIN map rollover
							  
sector = $(this).attr('ID');

$('#map_sectors img[class="' + sector + '"]').fadeIn('fast');

}, function(){
	
$('#map_sectors img[class*="sector"]').hide();

$('#map_sectors img.active').show();

});

// END map rollover

//BEGIN map click TO sector input change

$('#Map area').click(function() {
							  
$('#map_sectors img').removeClass('active');

sectorAlt = $(this).attr('alt');

$('#form_sector').val(sectorAlt);

sectorId = $(this).attr('ID');

$('#map_sectors img[class="' + sectorId + '"]').addClass('active');

$('#map_sectors img[class*="sector"]').hide();

$('#map_sectors img.active').show();

return false;

}); 

//END map click TO sector input change

// #top_picks

$.fn.jqPaginateUl = function(entriesPerPage) {//BEGIN .jqPaginateUl function
	
$this = $(this);

return $this.each(function(){//BEGIN .jqPaginateUl

$this.addClass('jqPaginateUl');

//var entriesPerPage = 8; // sets number of displayed entries per page 

var totalEntries = $('ul li', this).length;

if ( totalEntries != 1 ) { var pluralVar = 's' } else { var pluralVar = '' } 

$('.total_results').html(totalEntries + ' Result' + pluralVar + ' Found');


setNumbers = Math.ceil( totalEntries / entriesPerPage ); // determine how many sets need to be used, and round up to nearest integer

if ( totalEntries > entriesPerPage ) {//BEGIN populate .jqPaginateUl


//BEGIN split UL.

var getUl = $('ul', this),

    group = getUl.find('li:lt(' + entriesPerPage + ')', this).remove();
	
  while ( group.length ){

    $('<ul/>').append(group).appendTo($this);

    group = getUl.find('li:lt(' + entriesPerPage + ')', this).remove();

  };
	
$('ul:first-child', this).remove(); //END split UL

jqPaginateUlID = $(this).attr('id');

$(this).append('<p class="ul_index">Page <span class="jqPaginateUlCurrent">1</span> of ' + setNumbers + ' - </p>');

i=0;

comma = ', ';

$('ul', this).each(function(){//BEGIN give ID to each UL

							i++;

							$(this).attr('id', jqPaginateUlID + '_' + i);

							if ( i == setNumbers ) { comma = ''};

							$('p.ul_index', $this).append('<a href="#' + jqPaginateUlID + '_' + i + '">' + i + '</a>' + comma);				

							});//END give ID to each UL

$('p.ul_index a:first', $this).addClass('active');

} //END populate .jqPaginateUl

$('ul:not(:first-child)', $this).hide();

$('.jqPaginateUl p.ul_index a').click(function(){//BEGIN change page function

if ( $(this).hasClass('active') ) {return false;} else {

var targetString = $(this).attr('href');

var targetString = targetString.split('#');

var targetString = '#' + targetString[1];


$(this).parent().parent().children('ul').hide();

$('ul' + targetString).fadeIn('slow');

var targetInt = targetString.replace(/[^0-9\\.]/g, '').replace(/^(\d*\.\d*)\..*$/, "$1") * 1.0; //Extract number from targetString

$(this).parent().children('span.jqPaginateUlCurrent').html(targetInt);

$(this).parent().children('a').removeClass('active');

$(this).addClass('active');
	
	}
	
return false;										

});//END change page function

});//END .jqPaginateUl

}//END .jqPaginateUl function  

//BEGIN display A TAG for contact details and set up clear classes for all odd numbered LI elements

$('.lower_panel ul li div').each(function(){ $(this).before(' / <a class="jqContact" href="">contact details</a>');});

//END display A TAG for contact details

$('.lower_panel ul').each(function(){ //BEGIN set .clear on new line
							   						   
							   var ulWidth = $(this).width();			   
							   
							   if ( $('li', this).is(':hidden') ) { $(this).show(); var liWidth = $('li', this).width(); $(this).hide();}
							   
							   else { var liWidth = $('li', this).width(); }
							   
                               var perLine = Math.round ( ulWidth / liWidth );
							   						   
							   $('li:nth-child(' + perLine + 'n)', this).next().addClass('clear');
							   
							   }); //END set .clear on new line

//BEGIN toggle display contact details div

$(document).ready(function(){				   
						   
$('a.jqContact').toggle(function(e){ e.preventDefault(); $(this).parent().parent().children('li').children('div').slideUp('fast'); $(this).next('div').slideDown('fast');}, function(e){ e.preventDefault(); $(this).parent().parent().children('li').children('div').slideUp('fast');});						   

});//END toggle display contact details div

//END #top_links

//BEGIN .jqSlider

$('.jqSlider').each(function(){
							 
var $this = $(this);

totalSlides = $(this).children().length;

slideWidth = $('div', this).outerWidth(true);

containerWidth = slideWidth * totalSlides;

if ( totalSlides > 1 ) { //BEGIN wrap slides

$(this).children().wrapAll('<div class="jqContainer" />').parent().css({'width':containerWidth});
	
$this.prepend('<ul class="navi"></ul>');	
	
} //END wrap slides

$(this).children().children().each(function(){ //BEGIN get each slide's ID and populate ul.navi

var slideID = $(this).attr('id');

var slideAnchor = slideID.replace(/_/gi, " ");

$('ul.navi', $this).append('<li><a href="#' + slideID + '">' + slideAnchor + '</a></li>');

}); //END get each slide's ID and populate ul.navi

$('ul.navi', $this).append('<li class="accessibility"><a href="#header">Skip to Main Navigation</a></li>');

$('ul.navi a:first', $this).addClass('active');

$('ul.navi a', $this).click(function(){ //BEGIN slide function

var targetVar = $(this).attr('href');

var targetVar = targetVar.split('#');

var targetVar = '#' + targetVar[1];

pos = $(targetVar).position(); posTop = pos.top; posLeft = pos.left;

$('.jqContainer', $this).animate({'left':'-' + posLeft, 'top':'-' + posTop}, animSpeed * 2, animFX);

$('ul.navi a', $this).removeClass('active');

$(this).addClass('active');

return false;

}); //END slide function

}); //END .jqSlider



//BEGIN .jqProfileGallery
var j = 0;
$('.jqProfileGallery').each(function(){
	
$this = $(this);

j++;

if ( $this.attr('id').length > 0 ) { var thisID = $this.attr('id') }

else { var thisID = $this.attr('id', 'jqProfileGallery_' + j) }

//BEGIN create .jqProfileGallerythumbContainer

var totalProfiles = $this.children('div').length;

$this.append('<div id="' + thisID + '_thumbnails" class="jqProfileGalleryThumbContainer"></div><!--/_thumbnails-->');

//thisID = thisID + '_thumbnails';

//END create .jqProfileGallerythumbContainer

var i=0;

$this.children('div').each(function(){//BEGIN populate .jqProfileGallerythumbContainer

i++;

if ( i > totalProfiles) { return; }

else {//BEGIN get vars from each div and add to .jqProfileGallerythumbContainer
	
	var imgSrcVar = $('img', this).attr('src'),//BEGIN get image, h3 tag (name), and h4 tag (title) as vars
    imgAltVar = $('img', this).attr('alt'),
	nameVar = $('h3', this).html(),
	titleVar = $('h4', this).html();//END get image, h3 tag (name), and h4 tag (title) as vars
	nameIDvar = nameVar.toLowerCase().replace(' ','_');
		
	$(this).attr('id', i + '_' + nameIDvar);
	
	$this.children('div').last().append('<div class="jqProfileGalleryThumb"><a href="#' + i + '_' + nameIDvar + '"><img alt="' + imgAltVar + '" src="' + imgSrcVar + '" /><div class="jqProfileGalleryInfo"><p class="jqProfileGalleryName">' + nameVar + '</p><p class="jqProfileGalleryTitle">' + titleVar + '</p></div><!--/.jqProfileGalleryInfo--></a></div><!--/.jqProfileGalleryThumb-->');
	
	$('li ul li', this).each(function(){//BEGIN remove li elements that are empty
									  
									  if ( $(this).html() == '' ) { $(this).parent().parent().remove(); }
									  
									  });//END remove li elements that are empty



	}//END get vars from each div and add to .jqProfileGallerythumbContainer


position = $(this).position(),
  posTopMain = position.top,
 posLeftMain = position.left,
cssWidthMain = $(this).width();

$(this).hide();

});//END populate .jqProfileGallerythumbContainer
	
$('.jqProfileGalleryThumb a div.jqProfileGalleryInfo', $this).hide()

//BEGIN a tag functionality


$('.jqProfileGalleryThumb a', $this).hover(function(){

if ( $(this).hasClass('active') ) {return false;}													

$('.jqProfileGalleryInfo', this).stop(true, true).slideDown(animSpeed, animFX);

},

function(){

$('.jqProfileGalleryInfo', this).slideUp(animSpeed, animFX);

});

$('.jqProfileGalleryThumb a', $this).click(function(e){

e.preventDefault();

var position = $(this).parent().position(),
 posTopThumb = position.top,
posLeftThumb = position.left,
targetVar = $(this).attr('href'),
targetVar = targetVar.split('#'),
targetVar = '#' + targetVar[1],
cssWidthThumb = $(this).width();

if ( $(targetVar).hasClass('active') ) {return;}

else if ( !$('div.active', $this).is(':animated') || !$('.jqProfileGalleryThumb a', $this).is(':animated') ) {

$('.jqProfileGalleryThumb a', $this).removeClass('active').fadeTo('fast',1);

$(this).fadeTo('fast',0.5).addClass('active');

$('div.active', $this).animate({'top':-10, 'opacity':0}, animSpeed, animFX, function(){ $(this).removeClass('active').hide(); })

$(targetVar).css({'opacity':0, 'top':posTopThumb, 'left':posLeftThumb + 10, 'width':cssWidthThumb}).show() // +10 to offset the left position of the container

			.animate({'opacity':1, 'top':posTopMain, 'left':posLeftMain, 'width':cssWidthMain}, animSpeed, animFX).addClass('active');

return false;

}

});//END a tag functionality

});//END .jqProfileGallery

$(window).load(function(){//BEGIN wait for all page elements to load

$('.jqGallery').each(function(){ //BEGIN .jqGallery



//BEGIN get vars

var thumbnailCount = 2; // sets number of thumbnails on display

var setLoop = true; // sets slideshow to animate automatically

var intervalSpeed = 5000; // sets number of milliseconds delay between each animation

var $this = $(this);

var jqGalleryCount = $('img', this).length;

if ( thumbnailCount >= jqGalleryCount - 1 ) { thumbnailCount = jqGalleryCount - 2 }

var jqGalleryHeight = $this.height();

var jqThumbHeight = jqGalleryHeight / thumbnailCount;

//END get vars

if ( jqGalleryCount > ( thumbnailCount + 1 ) ) { //BEGIN Populate carousel

$this.after('<div class="jqGallery_carousel" style="height:' + jqGalleryHeight + 'px"><div class="jqGallery_container"></div></div>').each(function(){ //BEGIN clone each image
																																					
$('img', this).clone().appendTo( $this.next().children() ).css({'height':jqThumbHeight}).wrap('<div>');

}); //END clone each image

$this.next().append('<a class="jqGalleryNext" href="#next">Next</a>');

} //END Populate carousel

//BEGIN create Title and Caption panel by grabbing title and alt vars from each img

$('img', this).each(function(){
							 
var     $img = $(this),
	titleVar = $(this).attr('title'),
      altVar = $(this).attr('alt');

$img.attr('title','').attr('alt','');

$img.wrap('<div />').parent().append('<div class="jqGalleryInfo"><p class="jqGalleryTitle"></p><p class="jqGalleryCaption"></p></div>');

$img.next().children('.jqGalleryTitle').html(titleVar).parent().children('.jqGalleryCaption').html(altVar);

if ( titleVar == '' && altVar == '' ) { $img.next().remove() }

else if ( titleVar == '' ) { $img.next().children('.jqGalleryTitle').remove() }

else if ( altVar == '' ) { $img.next().children('.jqGalleryCaption').remove() }

var infoHeight = $img.next().outerHeight(true) + 10;

$img.next().css({'top':'-' + infoHeight + 'px'});

$img.parent().hover(function(){if ( !$('*', $this).not('.jqGalleryInfo').is(':animated') ) $img.next().stop().animate({'top':'0px'}, animSpeed, animFX);}, function(){$img.next().stop().animate({'top':'-' + infoHeight + 'px'}, animSpeed, animFX);});

});//END create Title and Caption panel by grabbing title and alt vars from each img

var $jqGallery_carousel = $this.next();

var $jqGallery_container = $jqGallery_carousel.children('div');

var borderOffset = parseInt($jqGallery_container.children().css('border-bottom-width') );

var borderOffset = borderOffset * thumbnailCount + borderOffset;

var jqThumbWidth = $($jqGallery_container).children().width();

$jqGallery_container.css({'bottom':'-' + jqThumbHeight - borderOffset + 'px'}); // subtract borderOffset var to account for img border-bottom

$jqGallery_carousel.css({'width':jqThumbWidth});

function jqGalleryRotator() {//BEGIN next function

if ( !$('div:last-child', $jqGallery_container).is(':animated') ) {//BEGIN check anim

$('div:last-child', $jqGallery_container).animate({'height':0}, animSpeed, function(){$(this).prependTo($jqGallery_container).height(jqThumbHeight)});

$('div:last-child img', $this).fadeOut(animSpeed, function(){$(this).parent().prependTo($this).children().show()});

} //END check anim

} //END next function

$jqGallery_carousel.hover(function(){$('a', $jqGallery_carousel).stop(true, true).slideDown('fast');}, function(){$('a', $jqGallery_carousel).stop(true, true).slideUp('fast');});

$('a', $jqGallery_carousel).hide().click(function(e){e.preventDefault(); jqGalleryRotator();});

if ( setLoop == true ) { //BEGIN loop

var timer = setInterval(jqGalleryRotator,intervalSpeed);

$this.hover(function(){clearInterval(timer)}, function(){timer = setInterval(jqGalleryRotator,intervalSpeed)});

$jqGallery_carousel.hover(function(){clearInterval(timer)}, function(){timer = setInterval(jqGalleryRotator,intervalSpeed)});

} //END loop

}); //END .jqGallery

});//END wait for all page elements to load

//BEGIN .jqCaption

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

var $this = $(this);

$this.find('p').wrapAll('<div />');

var $div = $this.find('div');

var divHeight = $div.outerHeight(true) + 3; 

var posBottom = parseInt($div.css('bottom'));

$div.css({'bottom':'-' + divHeight + 'px'});

$this.hover(function(){
					 
					 $div.stop().animate({'bottom':posBottom}, animSpeed, animFX);
					 
					 }, function(){$div.stop().animate({'bottom':'-' + divHeight + 'px'}, animSpeed, animFX)});

});//END .jqCaption


//BEGIN #star_form

$('#form_rating').after('<div id="form_stars" class="clear"><img src="images/sprite_stars.png" usemap="#star_map" /></div>');

starHeight = $('#form_stars').height();

$(document).ready(function(){

starValue = $('#form_rating').val(); starStep = starValue * starHeight; $('#form_stars img').css({'top':'-' + starStep + 'px'}); fixedStep = starStep;
				
					$('#star_map area').mouseover(function(){
														
								starValue = $(this).index() + 1;
						
								starStep = starValue * starHeight;
															
								$('#form_stars img').css({'top':'-' + starStep + 'px'});						
											
								})
					.mouseout(function(){ $('#form_stars img').css({'top':'-' + fixedStep + 'px'}); })
					
					.click(function(e){ e.preventDefault(); $('#form_rating').val(starValue); fixedStep = starStep; });

});//END document.ready

//END #star_form 

//BEGIN #quick_nav

if ( $('#quick_nav').length > 0 ) { $('body').css({'overflow-y':'scroll'}) }

var quicknavHeight = $('#quick_nav').height();

$('#quick_nav').before('<p class="quick_nav">&raquo; <a href="#">quick nav</a></p>').css({'height':0});

$('.quick_nav').toggle(function(){

$('#quick_nav').animate({'height':quicknavHeight}, animSpeed); return false;

}, function(){

$('#quick_nav').animate({'height':0}, animSpeed);

})

//END #quick_nav

//BEGIN ul.breadcrumb 

var matchVar = $('.breadcrumb li a.active').html();

$('#quick_nav ul li a:contains(' + matchVar + ')').addClass('active');

//END ul.breadcrumb

//BEGIN overlay

/*

if ( !$.browser.msie ) { // Overlay disabled in IE... sorry :(

var dWidth  = $(document).width(),
    dHeight = $(document).height();

$('body').append('<div class="jsOverlay" style="display:none; top:0; left:0; position:absolute; background:#eee; z-index:9998; width:' + dWidth + 'px; height:' + dHeight + 'px; cursor:pointer;"></div>')

$('.contact_form *').focus(function(){

if ( $(this).hasClass('image') ) { 

if ( !$.browser.opera ) {

$formVar.stop().animate({shadow: '0px 0px 0px #333', top: 0}, 'fast'); 

}

$('.jsOverlay').stop(true, true).fadeOut('fast', function(){ $formVar.removeAttr('style')}); 

return;}

$formVar = $(this).closest('form');

$formVar.css({'position':'relative','z-index':9999});

//get vars

$('.jsOverlay').fadeTo('fast', 0.7);

if ( !$.browser.opera ) {

$formVar.stop().animate({shadow: '0px 10px 15px #aaa', top: 3}, 'fast');

}

});

$('.jsOverlay').click(function(){ $(this).stop(true, true).fadeOut('fast', function(){ $formVar.removeAttr('style') ;}); 

if ( !$.browser.opera ) {

$formVar.stop().animate({shadow: '0px 0px 0px #333', top: 0}, 'fast');

}

});

}

*/

//END overlay

/* img.stamp */

noOfStamps = 7

var rng = Math.ceil(Math.random()* (noOfStamps));

if (rng == 0) {rng++;}

$('img.stamp').attr('src','images/stamps/' + rng + '_stamp.png'); 

/* #not_found */

/*

$('#not_found .new_block').hover(function(){

$(this).mousemove(function(e){

var wposX = e.pageX /10,
    wposY = e.pageY /10;

$('div.code_block').animate({'marginTop': + wposX, 'marginLeft': + wposY},'slow');
	
});

}, function(){ $('div.code_block').animate({'marginTop':0, 'marginLeft':0},'slow'); });

*/








$('#not_found div.new_block').hover(function(){

$('#not_found div.new_block').mousemove(function(e){

var newPosX = e.pageX / 50, // track new x pos of mouse
    newPosY = e.pageY / 10;
		
$('div.code_block').stop().animate({'marginLeft':'-' + newPosX, 'marginTop':'-' + newPosY},'slow');

});

}, function(){ $('div.code_block').stop().animate({'margin':0},'slow') });




































/* #sidebar */

// #testimonials

if ( !$('#testimonials').hasClass('static') ) {  

var indexVar = 0;

$('#testimonials blockquote').hide();

var totalVar = $('#testimonials blockquote').length; // get total number of testimonials

function timeout() {

		$('#testimonials blockquote').fadeOut(animSpeed);

		/*

		var blockHeight = $('#testimonials blockquote:eq('+indexVar+')').outerHeight( true ); // get height of blockquote

		blockHeight = blockHeight + 15; // add 15 to simulate padding bottom

		$('#testimonials').animate({'height':blockHeight + 'px'}, animSpeed, animFX); // animate #testimonial height to height of blockquote

		*/	

		$('#testimonials blockquote:eq(' + indexVar + ')').fadeIn(animSpeed);

		indexVar++;

		if ( indexVar == totalVar ) indexVar = 0;

        setTimeout('timeout()', 8000); 
    }

    timeout();
	
	}

/* #footer */
// #footer #subscribe

subscribe_var = 'Type Email Address';

$('#footer #subscribe_email').val(subscribe_var)

					   .click(function(){

						 if ( $(this).val() == subscribe_var )
						 
{$(this).val('').css({'text-transform':'lowercase'}) } }).blur(function(){ 

					   var current_var = $(this).val();

					   if ( current_var == '' ) { $(this).css({'text-transform':'uppercase'}).val(subscribe_var) }

					   

					   });

/* #header */

// #header ul.navi li a

$('#header ul.navi li a:not(.active)').mousedown(function(){$(this).stop().animate({'backgroundColor':'#ef46bd'}, animSpeed / 2)}).hover(function(){$(this).stop().animate({'backgroundColor':'#464646'}, animSpeed)}, function(){$(this).stop().animate({'backgroundColor':'#b5b5b5'}, animSpeed)});



$(function(){
	
/*
if ( !$('.logo a').hasClass('active') ) { $('.logo a').append('<img src="images/edit_optimisation_hover.jpg" alt="Edit Optimisation&trade;" style="z-index:-1">');}

$('.logo a').hover(function(){

if ( !$(this).hasClass('active') ) { $(this).children('img:first-child').stop().animate({'opacity':0}, 'slow'); }

}, function(){

$(this).children('img:first-child').stop().animate({'opacity':1}, 'slow');

});//.logo a hover

*/




$panel='';

$('a[href$="jpg"], a[href$="jpeg"], a[href$="gif"], a[href$="png"], a[href$="bmp"], a[href$="tif"], a[href$="tiff"], a[href$="webp"]').live('click',function(e){

var imgSrc = $(this).attr('href'),
   content = '<img alt="" src="' + imgSrc + '" />';

if ( imgSrc.indexOf('http://') >= 0 ) { return; } // prevents hotlinking to external images

jqModal(content);
	 
return false;

});//a[rel lightbox] click


// jqModal //

var bgOpacity = 0.8,
     animTime = 650;

if ( $('#jqOverlay').length < 1 ) { $('body').append('<div id="jqOverlay"><div id="jqModal"></div><div class="jqModalClose" id="jqOverlayBG"></div></div>'); }

var $jqOverlay   = $('#jqOverlay'),
    $jqModal     = $('#jqModal'),
	$jqOverlayBG = $('#jqOverlayBG');

$jqOverlay.hide();

$($jqOverlayBG, $jqModal).css('opacity',0);	
	
$(window).resize(function(){
	
	if ( $jqOverlay.is(':visible') ) { jqOverlayResize(); }
	
	});//window RESIZE



function jqOverlayCall() {
	
	$jqOverlay.show();
	
	jqOverlayResize();
	
	$jqOverlayBG.animate({'opacity':bgOpacity},animTime);
	
	$jqModal.css('top','50%').animate({'opacity':1},animTime);
	
	}//FN jqOverlayCall
	
	
	
function jqOverlayResize() {//sets positioning of #jqModal

       modalW = $jqModal.width(),
	   modalH = $jqModal.height(),
	   winW   = $(window).width(),
	   winH   = $(window).height();

$jqModal.css({'marginLeft':modalW/2 *-1,'marginTop':modalH/2 *-1});
	   
if ( modalW > winW ) { $jqModal.addClass('fixed-x') } else { $jqModal.removeClass('fixed-x') }  	   	

if ( modalH > winH ) { $jqModal.addClass('fixed-y') } else { $jqModal.removeClass('fixed-y') }	

	}//FN jqOverlayResize
		
	
	
function jqModal(content, callback) {
	
	$jqModal.css('opacity',0).html(content);//reduce opacity first to account for any images that may need to be loaded
	
	if ( $('img, object, embed', $jqModal).length ) {
		
		$('img, object, embed', $jqModal).load(function(){
			
			detectOverlay();
			
			});
		
		} else {
			
			detectOverlay();
			
			}
	
	function detectOverlay() {
		
		if ( $jqOverlay.is(':visible') ) { jqOverlayResize(); $jqModal.css('opacity',1) }  else { jqOverlayCall(); }
		
		}
		
	if (callback) { window[callback](); callback = null; }
			
	}//FN alertBox		

$(document).keyup(function(e){
	
	if (e.keyCode == 27 && $('.jqModalClose').is(':visible') ) { $('.jqModalClose').click(); }
	
	});
	

$('.jqModalClose').live('click',function(e){
	
	e.preventDefault();
	
	jqModalClose();
	
	});//.closeWindow LIVE CLICK


function jqModalClose(callback) {
		
	$jqModal.animate({'top':'48%','opacity':0},300);
	
	$jqOverlayBG.animate({'opacity':0}, 600, function(){
		
		$jqOverlay.hide();
		
		if (callback) { window[callback](); callback = null; }
		
		});//#jqOverlayBG ANIMATE
	
	}//FN closejqModal

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

$(this).blur();

msgBox('<p>Unfortunately this feature is not ready just yet, although we are working on it.<br/><br/>In the meantime, please visit our <a class="swap" href="contact.php">Contact Us</a> page to get in touch.<br/><br/>Thanks!</p>');

});//.not_ready

function msgBox(msg) {

var content = '<div class="msgBox">' + msg + '</div>';

jqModal(content);

}//fn msgBox

		

$('.player').live('mouseover',function(){
	
	$(this).find('img').stop(true,true).fadeIn('slow');
	
	}).live('mouseout', function(){
	
	$(this).find('img').stop(true,true).fadeOut('fast');
	
	}).live('click',function(e){
		
		e.preventDefault();
		
		jqModal('<div class="playerShell"><a id="player" class="loading" href="editoptimisation.mp4"></a></div>');
		
		$f("player", {src: 'includes/scripts/flowplayer.commercial-3.1.5.swf', wmode: 'transparent'} ,{
	clip: { onFinish:function(){ $('.jqModalClose').click(); }},	
	  key: '#@d209ecde86e4867372e', plugins: {
	  controls: {
		  timeBorderColor : '#ffffff',
		  buttonOverColor : '#EF46BD',
		  buttonColor : '#777777',
		  timeColor : '#EF46BD',
		  durationColor : '#777777',
		  timeBgColor : '#ffffff',
		  progressColor : '#EF46BD',
		  bufferColor : '#777777',
		autoHide: 'always',
			hideDelay: 1000,
		backgroundColor: '#ffffff'
	  }}});
	  
		})//#player
		





$('.jqModalClose').live('click', function(){
			
		    jqModalClose(resetPlayer());
				
			})//fn closePlayer
			
			
			function resetPlayer() {
				
				$('.playerShell').fadeOut('fast', function(){
					
					$(this).remove();
					
					})
				
				}
		
		
			
$('#client_login label, #client_login input').focus(function(){
	
	var getVal = $(this).closest('.relative').find('input').val();
	
	 if ( getVal.length === 0 ) { $(this).closest('.relative').find('label').fadeTo('fast',0.4); } 
	 
	 else { $(this).closest('.relative').find('label').fadeOut('fast',0); }
	
	}).keyup(function(){
			
			var getVal = $(this).val();
			
			if ( getVal.length > 0 ) { $(this).closest('.relative').find('label').fadeOut(0) }
			
			else {  $(this).closest('.relative').find('label').fadeIn('fast') }
			
			}).blur(function(){
		
		var getVal = $(this).closest('.relative').find('input').val();
	
	if ( getVal.length === 0 ) { $(this).closest('.relative').find('label').fadeTo('fast',1); }
		
		});

});//fn document ready
