var numScrollItems = 0;
var currentScrollItem = 1;
var slideScrollType = 1;


$(function() {
	if($.browser.msie){
		if(jQuery.browser.version!=8.0){

			$('#content_right_float h3').addClass('shadow');
			
			$('#icon_flexible_offices, #icon_meeting_rooms, #icon_virtual_offices,#content_right_float #testimonial_header, #content_right_float #testimonial_body, #content_right_float #testimonial_footer,#enquiry_flexible_office,#enquiry_meeting_room,#enquiry_virtual_office').addClass('shadow');
			$('#right_menu').addClass('shadow');
			$('#right_features').addClass('shadow');
			$('#right_features h3').removeClass('shadow');
			$('#right_menu').css('margin-bottom','20px');
			$('#right_features h3').css('height','20px');
			$('#right_features h3').css('margin-top','-10px');
			$('#icon_flexible_offices, #icon_meeting_rooms, #icon_virtual_offices').css('margin-bottom','10px');
	
	
			$('.rounded, .shadow').each(function() {
				PIE.attach(this);
			});

		}
	}
	

/*		$("#header_tabs li a").mouseout(function(){
			  $(this).animate({
				'padding-top': '68px',
			  }, 250, function() { });
		}).mouseover(function(){
			  $(this).animate({
				'padding-top': '80px',
			  }, 250, function() { });
		});*/

		$("#button1,#button2,#button3").mouseout(function(){
			  $(this).stop().animate({
				opacity: 0
			  }, 250);
		}).mouseover(function(){
			  $(this).stop().animate({
				opacity: 1
			  }, 250);
		});

		$('#button1').click(function(){ 
				$('#image2').animate({marginLeft: "0px"}, { queue:false, duration:400, easing: 'easeOutSine' });
				$('#image3').animate({marginLeft: "0px"}, { queue:false, duration:400, easing: 'easeOutSine' });
		});
		
		$('#button2').click(function(){ 
				$('#image2').animate({marginLeft: "-405px"}, { queue:false, duration:400, easing: 'easeOutSine' });
				$('#image3').animate({marginLeft: "0px"}, { queue:false, duration:400, easing: 'easeOutSine' });
		});

		$('#button3').click(function(){ 
				$('#image2').animate({marginLeft: "-405px"}, { queue:false, duration:400, easing: 'easeOutSine' });
				$('#image3').animate({marginLeft: "-405px"}, { queue:false, duration:400, easing: 'easeOutSine' });
		});

		$('#header_flexible-offices')
				.mouseover(function(){
						$(this).css({backgroundPosition: "0px 12px"});
						$(this).stop().animate({backgroundPosition:"(0px 7px)"}, {duration:250})
				})
				.mouseout(function(){
					$(this).stop().animate({backgroundPosition:"(0px 12px)"}, {duration:150, complete:function(){
					}})
				})

		$('#header_meeting-rooms')
				.mouseover(function(){
						$(this).css({backgroundPosition: "-110px 12px"});
						$(this).stop().animate({backgroundPosition:"(-110px 7px)"}, {duration:250})
				})
				.mouseout(function(){
					$(this).stop().animate({backgroundPosition:"(-110px 12px)"}, {duration:150, complete:function(){
					}})
				})

		$('#header_virtual-offices')
				.mouseover(function(){
						$(this).css({backgroundPosition: "-220px 12px"});
						$(this).stop().animate({backgroundPosition:"(-220px 7px)"}, {duration:250})
				})
				.mouseout(function(){
					$(this).stop().animate({backgroundPosition:"(-220px 12px)"}, {duration:150, complete:function(){
					}})
				})

		$('.active a').unbind('mouseover');
		$('.active a').unbind('mouseout');

			
/*		if($.browser.msie){
			if(jQuery.browser.version==7.0){
				$('#content_right_float').css('margin-top','-'+($('#inner_image').innerHeight()-10))
			}else{
				$('#content_right_float').css('margin-top','-'+($('#inner_image').innerHeight()))
			}
		}else{
			$('#content_right_float').css('margin-top','-'+$('#inner_image').css('height'))
		}
		
		$('#content_right_float').css('height',$('#content_right_float').innerHeight()-279);

*/
		if($('#inner_image img').length==1){
			$('#content_right_float').css('height',$('#content_right_float').innerHeight()-279);
		}
		$('#content_left_inner').css('height',($('#content_left_inner, #content_right_float').tallestSize()+10));
		if($('#inner_image img').length==0){
			$('#content_right_float').css('top','0px')
		}
		$('#priceBox').css('width',$('#price').innerWidth()+2+'px');
		
	//	alert($('#content_left_inner, #content_right_float').tallestSize());



		createSlideScrollComponent()
	

});

	function updatePagination() {
		/*
		* 	Changes the currently highlighted page number
		*/
		
		var elem = currentScrollItem;
		
		// adjust the current item number for 2 paragraph elements
		if (slideScrollType == 2 && elem > 1) {
			elem = (elem + 1) / 2;
		}
		
		// Clear current highlighted element
		$('#slideScrollPagination .slideScrollPaginationDigit').removeClass('current');
		
		// Set the current element
		$('#slideScrollPagination .slideScrollPaginationDigit:nth-child('+elem+')').addClass('current');
		
	}
	
	function createSlideScrollComponent() {
		/*
		* 	Initialises the SlideScroll component.
		*	NB. There are two version wrapped in here. 'client endorsements' uses 2 paragraphs for each item, the regular version uses only 1.
		*/
		
		var elem = 0;

		if ($('#slideScrollContentWrapper').is(":visible")) {
			
			// Set the component type
			//var strHeading = $('#slideScrollHeading').text();
			//if (strHeading == 'what our clients say') {
				slideScrollType = 2;
			//}
			
			// Add the quote marks and the Next/Prev buttons
			if (slideScrollType == 2) {
				$('#slideScrollContentWrapper').addClass('closeQuote');
				$('#slideScrollContentWrapper').append('<div id="slideScrollQuoteTop"></div>');
			}
			
			$('#slideScrollContentWrapper').append('<div id="slideScrollLeft"><a href="#slideLeft" title="previous"></a></div>');
			$('#slideScrollContentWrapper').append('<div id="slideScrollRight"><a href="#slideRight" title="next"></a></div>');
			
			// Calculate the number of items.
			// NB> For the 'our reputation page' there are 2 items for each quote
			if (slideScrollType == 2) {
				numScrollItems = $('#slideScrollContent p').length;
			} else {
				numScrollItems = $('#slideScrollContent table').length;
			}
			
			// Show the first item
			if (slideScrollType == 2) {
				$('#slideScrollContent p:nth-child(1)').show();
				$('#slideScrollContent p:nth-child(2)').show();
			} else {
				$('#slideScrollContent table:nth-child(1)').show();
			}
			
			// Add the pagination
			$('#slideScrollBody').append('<div id="slideScrollPagination"></div>');
			elem = numScrollItems;
			if (slideScrollType == 2) {
				elem = elem / 2;
			}
			for(i=1; i<=elem; i=i+1) {
				$('#slideScrollPagination').append('<span class="slideScrollPaginationDigit">' + i + '</span>');
			}
			updatePagination();
			
			// Create the button handlers
			if (slideScrollType == 2) {
				$('#slideScrollRight a').bind('click',function(event) {
					$('#slideScrollContent p:nth-child('+currentScrollItem+')').fadeOut();
					$('#slideScrollContent p:nth-child('+(currentScrollItem+1)+')').fadeOut('normal', function() {
						// Animation complete.
						currentScrollItem = currentScrollItem + 2;
						if (currentScrollItem > numScrollItems) {
							currentScrollItem = 1;	
						}
						$('#slideScrollContent p:nth-child('+currentScrollItem+')').fadeIn();
						$('#slideScrollContent p:nth-child('+(currentScrollItem+1)+')').fadeIn();
						updatePagination();
					});
				});
				
				$('#slideScrollLeft a').bind('click',function(event) {
					$('#slideScrollContent p:nth-child('+currentScrollItem+')').fadeOut();
					$('#slideScrollContent p:nth-child('+(currentScrollItem+1)+')').fadeOut('normal', function() {
						// Animation complete.
						currentScrollItem = currentScrollItem - 2;
						if (currentScrollItem < 1) {
							currentScrollItem = numScrollItems - 1;	
						}
						$('#slideScrollContent p:nth-child('+currentScrollItem+')').fadeIn();
						$('#slideScrollContent p:nth-child('+(currentScrollItem+1)+')').fadeIn();
						updatePagination();
					});
				});
			} else {
				$('#slideScrollRight a').bind('click',function(event) {
					$('#slideScrollContent table:nth-child('+currentScrollItem+')').fadeOut('normal', function() {
						// Animation complete.
						currentScrollItem = currentScrollItem + 1;
						if (currentScrollItem > numScrollItems) {
							currentScrollItem = 1;	
						}
						$('#slideScrollContent table:nth-child('+currentScrollItem+')').fadeIn();
						updatePagination();
					});
				});
				
				$('#slideScrollLeft a').bind('click',function(event) {
					$('#slideScrollContent table:nth-child('+currentScrollItem+')').fadeOut('normal', function() {
						// Animation complete.
						currentScrollItem = currentScrollItem - 1;
						if (currentScrollItem < 1) {
							currentScrollItem = numScrollItems;	
						}
						$('#slideScrollContent table:nth-child('+currentScrollItem+')').fadeIn();
						updatePagination();
					});
				});
			}
		}
	}

