/**
 * Chiquita scripts
 * 
 */


// PAGE LOAD

	$(document).ready(function() {
						
		$('#calculator table').calculator();
		
		$('.clearMeOnFocus').clearFieldOnFocus();
		
		$('.tabs').tabs();		
		
		$('.lnk-info-pop').infopop();
		
		$('.dock').jqDock({align:'middle',coefficient:1.5,distance:60,duration:200,size:84,labels:'bl'});
		
		$('.nav-local').each(function() {
			var img = $(this).children('a').children('b').css('backgroundImage').split('url(').join('').split(')').join('');
			//$('body').append('<img src="'+img+'" style="display:none;" id="navLocalImg" />');
			var w = $('#navLocalImg').width();
			if(w > 20) $(this).css('width', w);
			$('#navLocalImg').remove();
		});
		
		$('.box-overview-2').overviewBox();
		$('.box-overview-3').overviewBox();
		$('.box-overview-4').overviewBox();
		$('.box-clickable').overviewBox();

		$("a[href='#blog_floating_banana']").click(function(evt) {
			$('#blog_floating_banana').toggle();
			evt.preventDefault();
	  });
		
		$('.more-about-smoothies').mouseover(function(evt) { $('#products-smoothies-rollover').fadeIn(); evt.preventDefault(); }).mouseout( function(evt) { $('#products-smoothies-rollover').fadeOut(); evt.preventDefault(); });

    $('h1.sifr').flashTitle({ 
				css: ['* { color: #b2bb1e; }','strong { color: #b2bb1e; }','em { color: #f1932c; font-weight: bold; }','span { color: #fdb813; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'});
    $('h1.sifr-yellow').flashTitle({ 
				css: ['* { color: #fdb813; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'});		
    $('h2').flashTitle({ 
				css: ['* { color: #b2bb1e; }','strong { color: #fdb813; }','em { color: #f1932c; }'].join(' '),
				rotation:'0',textHeight:'20',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});   
	  $('h3').flashTitle({ 
				css: ['* { color: #f08b1d; }','strong { font-weight:bold; }','em { color: #f1932c; font-weight:bold; }','span { color: #e31b23; }'].join(' '),
				rotation:'0',textHeight:'16',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});	
    $('h4.red').flashTitle({ 
				css: ['* { color: #e31b23; }','strong { font-weight:bold; }'].join(' '),
				rotation:'0',textHeight:'16',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});		
    $('h4.red-L').flashTitle({ 
				css: ['* { color: #e31b23; }','strong { font-weight:bold; }'].join(' '),
				rotation:'0',textHeight:'20',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});				
		// titles about us
    $('h1#sifr-history').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'light'
		});
		$('h1#sifr-history-2, h1#sifr-history-3').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'light'
		});	
    $('h1#sifr-miss-chiquita').flashTitle({ 
				css: ['* { color: #fdb813; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'bold'
		});
    $('h1#sifr-bananas-and-more-1').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'light'
		});   
		$('h1#sifr-bananas-and-more-2').flashTitle({ 
				css: ['* { color: #f1932c; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'bold'
		});
	
    $('h1#sifr-media-library-1').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'light'
		});		
    $('h1#sifr-media-library-2, h1#sifr-media-library-3').flashTitle({ 
				css: ['* { color: #f1932c; }'].join(' '),
				rotation:'-3',textHeight:'34',verticalOffset:'3',horizontalOffset:'0',myFontWeight:'bold'
		});		
	  // titles products
    $('h1#sifr-bananas').flashTitle({ 
				css: ['* { color: #fdb813; }'].join(' '),
				rotation:'-3',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});
    $('h1#sifr-fruit').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'-3',textHeight:'30',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'regular'
		});	
    $('h1#sifr-smoothies').flashTitle({ 
				css: ['* { color: #f08b1d; }'].join(' '),
				rotation:'-3',textHeight:'30',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'regular'
		});		
    $('h1#sifr-freshfruit').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'-3',textHeight:'30',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'regular'
		});		
		// titles our commitment
    $('h1#h1-corporate-responsibility-1').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'light'
		});		
    $('h1#h1-corporate-responsibility-2').flashTitle({ 
				css: ['* { color: #f08b1d; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'

		});		
    $('h1#h1-nature-community-1').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'light'
		});				
    $('h1#h1-nature-community-2').flashTitle({ 
				css: ['* { color: #f08b1d; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});		
    $('h1#h1-rfa').flashTitle({ 
				css: ['* { color: #b2bb1e; }'].join(' '),
				rotation:'0',textHeight:'30',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});				

	
	//titles fruitbar
    $('h1#sifr-fruitbar-1').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'0',textHeight:'18',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'regular'
		});				
    $('h1#sifr-fruitbar-2').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'-4',textHeight:'40',verticalOffset:'0',horizontalOffset:'0',myFontWeight:'bold'
		});
    $('h1#sifr-fruitbar-3').flashTitle({ 
				css: ['* { color: #e31b23; }'].join(' '),
				rotation:'-4',textHeight:'40',verticalOffset:'5',horizontalOffset:'0',myFontWeight:'bold'
		});

	});

// CALCULATOR: Chiquita professionals > Food Solutions
	
			function isNumber(v) {
				var result = (Number(v)==v)? true:false;
				return result;
			} 
			function restrictToNumber(input) {
			 if (isNumber(input.val())) {
				input.data('prevVal',input.val());
			 } else {
				input.val(input.data('prevVal')); 
			 } 
			}
					
			
			jQuery.fn.extend({
					calculator: function() {
						
						// tekst uit element halen en omzetten naar nummer
						function v(el) {			 
							return Number($(el).text());	
						}	
						
						// nr afronden op 2 decimalen
						function r(nr) {
							return Math.round(100*nr)/100;	
						}
								
						return this.each(function() {
																		 
							$table = $(this);				
							$results = $('#results',$table);
							$buttons = $('a.lnk-more',$table);	
							$input = $('input.txt',$table);		
							
							var wasteMargin     = '#waste_margin';
							var labourCostHour  = '#labour_cost_hour';				
							var mPurchasePrice  = $('tr.m_purchase_price td',$table);
							var mCuttingYield   = $('tr.m_cutting_yield td',$table);
							var mTot            = $('tr.m_tot td',$table);  
							var lGross          = $('tr.l_gross td',$table); 
							var lNet            = $('tr.l_net td',$table);
							var lTot            = $('tr.l_tot td',$table);
							var hCleaning       = $('tr.h_cleaning td',$table);
							var hWaste          = $('tr.h_waste td',$table);
							var hIndirect       = $('tr.h_indirect td',$table);
							var hTot            = $('tr.h_tot td',$table);
							var yourTot         = $('tr.tot td',$table);
							var chiquitaTot     = $('tr.chiquita_tot td',$table);
							var yourSaving      = $('tr.saving td',$table);
											
							$buttons.each(function(i) {
								$(this).click(function (e) { updateValues(i); });
							});	
												
							$input.each(function(i) {
								$o = $(this);
								$o.val('0.00'); 
								$o.data('prevVal',$(this).val());
								//events
								$o.blur(function (e) { updateValues(i); });						
								$o.keyup(function() { restrictToNumber($(this)) });
							});	
			
							function initValues() {
							
								$input.each(function(i) {
									$(lGross[i]).text( r(v(lNet[i])*100/v(mCuttingYield[i])) ); 
									$(lTot[i]).text( r(v(labourCostHour)/v(lNet[i])) ); 
									$(hCleaning[i]).text( r(20/12/v(lNet[i])) ); // 5min/h  ???  moet dat niet 22euro*5/60 zijn - vanwaar komt die 20
									$(hWaste[i]).text( r((100-v(mCuttingYield[i]))/v(mCuttingYield[i])*0.05) ); 
									$(hTot[i]).text( r(v(hCleaning[i])+v(hIndirect[i])+v(hWaste[i])) ); 
								});
					
								$results.hide();
							};
							initValues();
			
							function updateValues(i) {
								
								input = $($input[i]).val();
							
								if (input>0) { 
									$(mPurchasePrice[i]).text( input ); 				 
									$(mTot[i]).text( r(100*(v(mPurchasePrice[i])/(1-(v(wasteMargin)*0.01)))/v(mCuttingYield[i])) ); 
									$(yourTot[i]).text( r(v(mTot[i])+v(lTot[i])+v(hTot[i])) ); 
									$(yourSaving[i]).text( r(100*(v(yourTot[i])-v(chiquitaTot[i]))/v(yourTot[i])) +'%'); 
								} else {
									$(mPurchasePrice[i]).text('-'); 				 
									$(mTot[i]).text('-'); 
									$(yourTot[i]).text('-'); 
									$(yourSaving[i]).text('-'); 
								}
								/*
								)
								()
								()
								*/
								$results.show();
								
							};
							
							
						});
					}
				});






// NEWSLETTER AJAX AND VALIDATION

	var to;
	function validateNewsletter() {
		var field = $('#newsletterFormEmail');
		if(!isEmail(field.attr('value'))) {
		
			field.addClass('invalid');
		
		} else {
			
			// show loader
				$('#newsletter-loader').slideDown();
			
			// reset values
				field.removeClass('invalid');
				$('#newsletter-thx').slideUp();
				$('#newsletter-error').slideUp();
				clearTimeout(to);
			
			// do ajax call
				var url = '/lib/ajax.saveNewsletter.php';
				var post = '&e='+field.attr('value')+'&l='+l;
				$.post(url, post, function(r) {
					var ret = r;
					$('#newsletter-loader').slideUp(function() {
						if(ret == '') {
							$('#newsletter-thx').slideDown();
							to = setTimeout(function() {
								$('#newsletter-thx').slideUp();
								field.attr('value', '').blur();
							},5000);
						} else {
							$('#newsletter-error').slideDown();
							to = setTimeout(function() {
								$('#newsletter-error').slideUp();
								field.attr('value', '').blur();
							},5000);
						}
					});
					// google tracker
					pageTracker._trackPageview('/'+langDomain+'/'+langShort+'/saveNewsletter');
				});
			
		}
	}


// SUBMIT CONTACT FORM
	
	function submitContactForm() {
		
		// hide previous errors
			hideContactFormErrors();
			var err = false;
		
		// check values
			if($('#txt_name').attr('value') == '') err = showContactFormError('txt_name');
			if($('#txt_surname').attr('value') == '') err = showContactFormError('txt_surname');
			if(!isEmail($('#txt_email').attr('value'))) err = showContactFormError('txt_email');
			if($('#txa_comments').attr('value') == '') err = showContactFormError('txa_comments');
		
		// if no problems, continue
			if(!err) {
				
				// show loader
					$('#contact-loader-bg').css('opacity', '0.7');
					$('#contact-loader').show();
					$('#contact-error').hide();
				
				// settings
					var url = '/lib/ajax.saveContactForm.php';
					var post = '';
					post += '&name_f='+$('#txt_name').attr('value');
					post += '&name_l='+$('#txt_surname').attr('value');
					post += '&email='+$('#txt_email').attr('value');
					post += '&comments='+$('#txa_comments').attr('value');
					post += '&l='+l;
				
				// save values
					$.post(url, post, function(r) {
						$('#contact-loader').hide();
						if(r == 'false') {
							$('#contactForm form').show();
							$('#contact-error-system').show();
						} else {
							$('#contact_intro').hide();
							$('#contactForm').html(r)
						}
						// google tracker
						pageTracker._trackPageview('/'+langDomain+'/'+langShort+'/contactFormSubmit');
					});
				
			}
		
	}
	
	function hideContactFormErrors() {
		hideContactFormError('txt_name');
		hideContactFormError('txt_surname');
		hideContactFormError('txt_email');
		hideContactFormError('txa_comments');
		return false;
	}
	
	function hideContactFormError(fld) {
		$("label[for='"+fld+"']").removeClass('invalid');
		$('#'+fld).removeClass('invalid');
	}
	
	function showContactFormError(fld) {
		$("label[for='"+fld+"']").addClass('invalid');
		$('#'+fld).addClass('invalid');
		$('#contact-error').show();
		$('#contact-error-system').hide();
		return true;
	}


// LOGIN FORM VALIDATION FUNCTIONS
	
	function validateLogin() {
		
		// hide previous errors
			hideLoginFormErrors();
			var err = false;
		
		// check fields
			if($('#txt_login').attr('value') == '') err = showLoginFormError('txt_login');
			if($('#txt_password').attr('value') == '') err = showLoginFormError('txt_password');
		
		// if no errors, continue
			if(!err) {
				
				// show loader
					$('#login-loader-bg').css('opacity', '0.7');
					$('#login-loader').show();
					$('#error-message-fields').hide();
					$('#error-message').hide();
				
				// settings
					var url = '/lib/ajax.login.php';
					var post = '';
					post += '&login='+$('#txt_login').attr('value');
					post += '&pass='+$('#txt_password').attr('value');
					post += '&l='+l;
				
				// check for login+password combination
					$.post(url, post, function(r) {
						$('#login-loader').hide();
						if(r == 'false') {
							$('#error-message').show();
						} else {
							window.location = $('#professionalLoginForm').attr('action');
						}
					});
				
			}
		
	}
	
	function hideLoginFormError(fld) {
		$("label[for='"+fld+"']").removeClass('invalid');
		$('#'+fld).removeClass('invalid');
	}
	
	function hideLoginFormErrors() {
		hideLoginFormError('txt_login');
		hideLoginFormError('txt_password');
		return false;
	}
	
	function showLoginFormError(fld) {
		$("label[for='"+fld+"']").addClass('invalid');
		$('#'+fld).addClass('invalid');
		$('#error-message-fields').show();
		$('#error-message').hide();
		return true;
	}


// REGISTER FORM VALIDATION FUNCTIONS

	function validateRegister() {
		
		// hide previous errors
			hideRegisterFormErrors();
			var err = false;
		
		// check fields
			if($('#txt_name').attr('value') == '') err = showRegisterFormError('txt_name');
			if($('#txt_surname').attr('value') == '') err = showRegisterFormError('txt_surname');
			if(!isEmail($('#txt_email').attr('value'))) err = showRegisterFormError('txt_email');
		
		// if no errors, continue
			if(err) return false;
			else return true;
		
	}
	
	function submitRegister() {
		if(validateRegister()) $('#professionalRegisterForm').submit();
	}
	
	function hideRegisterFormError(fld) {
		$("label[for='"+fld+"']").removeClass('invalid');
		$('#'+fld).removeClass('invalid');
	}
	
	function hideRegisterFormErrors() {
		hideLoginFormError('txt_name');
		hideLoginFormError('txt_surname');
		hideLoginFormError('txt_email');
		return false;
	}
	
	function showRegisterFormError(fld) {
		$("label[for='"+fld+"']").addClass('invalid');
		$('#'+fld).addClass('invalid');
		$('#register-error').show();
		return true;
	}


// GENERAL VALIDATION FUNCTIONS

	function validateSearch() {
		var field = $('#q');
		if(field.attr('value') == '' || field.attr('value').length <= 3) {
			field.addClass('invalid');
		} else {
			field.removeClass('invalid');
			document.searchForm.submit();
		}
	}
	
	function isEmail(v) {
		return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(v);
	}


// FLASH TITLES

	var fontFaceSwf = (l == 8) ? '/swf/sifr/tahoma.swf' : '/swf/sifr/bree.swf';
	jQuery.fn.extend({
		flashTitle: function(opts) {
			return this.each(function() {
				 $(this).flash(
						{ 
								src: fontFaceSwf, 
								wmode: 'transparent',
								flashvars: opts	
						},
						{ update: false },
						function(htmlOptions) {
								htmlOptions.flashvars.txt = this.innerHTML;
								this.innerHTML = '<div>'+this.innerHTML+'</div>';
								var $alt = $(this.firstChild);
								htmlOptions.height = $alt.height();
								htmlOptions.width = $alt.width();
								$alt.addClass('alt');
								$(this).addClass('flash-replaced').prepend($.fn.flash.transform(htmlOptions));						
						}
				);

			});
		}
	});
	
	
// OVERVIEW BOXES - Trigger inner link onclick of DIV container
	
	jQuery.fn.extend({
		overviewBox: function() {
			return this.each(function() {
			  $(this).mouseover(function() { 
						$(this).css('cursor','pointer'); $(this).find('a').addClass('hover'); 
						if ( $(this).hasClass('box-overview-2-other') ) { $('#products-superfruit-rollover').hide(); $('#products-other-rollover').fadeIn(); }
						if ( $(this).hasClass('box-overview-2-superfruit') ) { $('#products-other-rollover').hide(); $('#products-superfruit-rollover').fadeIn(); }
				}).mouseout(function() { 
						$(this).find('a').removeClass('hover'); 
						//if ( $(this).hasClass('box-overview-2-other') ) { setTimeout("$('#products-other-rollover').fadeOut();",5000); }
						//if ( $(this).hasClass('box-overview-2-superfruit') ) { setTimeout("$('#products-superfruit-rollover').fadeOut();",5000); }
				});
				$(this).click(function() { window.location = $(this).find('a').attr('href'); });
			});
		}
	});
	
	
// CLEAR FIELD ON FOCUS
	
	jQuery.fn.extend({
		clearFieldOnFocus: function() {
			return this.each(function() {
				if($(this).attr('rel') == undefined) $(this).attr('rel', $(this).attr('value'));
				$(this).focus(function() { if($(this).attr('value') == $(this).attr('rel')) $(this).attr('value', ''); });
				$(this).blur(function() { if($(this).attr('value') == '') $(this).attr('value', $(this).attr('rel')); });
			});
		}
	});
	

// INFO POP UP

	jQuery.fn.extend({
		infopop: function() {
			return this.each(function() {
				$(this).click(function(e) {
					var popupId = $(this).attr('href').replace('#','');		
					var posLeft = Math.round(e.pageX+10);
					var posTop =  Math.round(e.pageY+10);					
				  if ( $('#info-pop-overlay').get() == '') {
					  overlay = $('<div id="info-pop-overlay"><div class="info-pop-top"></div><div class="info-pop-mid"><a href="#" class="info-pop-close">X</a><div class="info-pop-content"></div></div><div class="info-pop-bottom"></div></div>');
					} else { overlay = $('#info-pop-overlay'); }		
					$('.info-pop-content',overlay).html($('#'+popupId).html());
					overlay.css({left:posLeft, top:posTop}).appendTo(document.body).fadeIn();
				  $('.info-pop-close',overlay).click( function(e) {
						$('#info-pop-overlay').fadeOut();															 
					});
					e.preventDefault();
				});				 
			});
		}
	});	


	jQuery.fn.extend({
		callout: function(options) {
			
			settings = jQuery.extend({
				 position: 'bottom',  // position callout bottom|top of link
				 containerClass: '',  // additional css class to modify layout
				 width: 390,          
				 hOffset: 20,         // horizontal offset
				 vOffset: 20 			    // vertical offset
			}, options);
			
		  return this.each(function() {
				$(this).click(function(e) {
															 
					var contentId = $(this).attr('href').replace('#','');  // id of container that contains content for callout	
					var hPos;
					var vPos;
					var $callout;
					
		      // insert callout div if it doesn't exist
				  if ( $('#callout').length == 0 ) { 
					  $callout = $('<div id="callout" class="callout-'+settings.position+' '+settings.containerClass+'"><a href="#" class="close-button">X</a><div class="callout-content"></div></div></div>'); 
						$callout.css({'position':'absolute','z-index':999,'left':'-9999px','top':'-9999px'}).appendTo(document.body);
					} 
					else { $callout = $('#callout'); }	
					
          // insert content and set width
					$('.callout-content',$callout).html($('#'+contentId).html());
					$callout.css({'width':settings.width+'px'});					
				  // now we can get the height to calculate positions
					hPos = Math.round(e.pageX+settings.hOffset);
					vPos = Math.round(e.pageY+settings.vOffset);
					if (settings.position == 'top') {
					  vPos = Math.round(vPos-$callout.height());					
					}
					$callout.css({'left':hPos, 'top':vPos+'px'}).appendTo(document.body).fadeIn();        
					
				  $('.close-button').click( function(e) {
						$callout.fadeOut();	e.preventDefault();													 
					});
					e.preventDefault();
				});				 
			});
			
			
		}
	});	
	
// CENTERED OVERLAY

	jQuery.fn.extend({
		overlay: function(settings) {
			return this.each(function() {
															
				$(this).click(function(e) { 
					var popupId = $(this).attr('href').replace('#','');		
					//var posLeft = Math.round(e.pageX+10);
					//var posTop =  Math.round(e.pageY+10);					
				  if ( $('#centered-overlay').get() == '') {
					  overlay = $('<div id="centered-overlay"><div class="overlay-topleft"><div class="overlay-topright"><a href="#" class="overlay-close">X</a></div></div><div class="overlay-content"></div><div class="overlay-bottomleft"><div class="overlay-bottomright"></div></div></div>');
					} else { overlay = $('#centered-overlay'); }		
					$('.overlay-content',overlay).html($('#'+popupId).html());
					overlay.css({width: settings.width, height: settings.height, left: settings.left, top:settings.top}).appendTo('#content').fadeIn();
					overlay.appendTo('#content').fadeIn();
				  $('.overlay-close',overlay).click( function(e) {
						$('#centered-overlay').fadeOut();															 
					});
					e.preventDefault();
				});				 
			});
		}
	});	

// TABS

	jQuery.fn.extend({
		tabs: function() {
			return this.each(function() {
				//
				var contentItems 		 = $('.tab-content-item',$(this));
				var tabItems     		 = $('.tab-nav li a',$(this));
				var contentContainer = $('.tab-content');
				var initTab				   = $(contentItems[0]).attr('id');
				var activeTab    		 = '';
				var contentHeight = 180;
				var activeId;
				// init
				init = function() {
					var hash = window.location.hash.replace('#','');
					contentItems.each( function() {	
						var h = $(this).height();	
						if ( h > contentHeight ) contentHeight = h; // get max content item height		
						if ( $(this).attr('id') == hash ) initTab = hash;	// check if hash corresponds with content item id		
					});		
					//contentContainer.height(contentHeight-50); 
					// click event tab items
					tabItems.each( function() {
						$(this).click(function(e){ 
							//$('.tab-content-item').stop();										 
							var id = $(this).attr('href').replace('#','');
							showTab(id);
							e.preventDefault();
						});												 
					});
					showTab(initTab);
				};
				// show tab
				showTab = function(id) {
					jQuery.fn.tabs.activeId = id;					
					contentItems.each( function(i) {
						if ( $(this).attr('id') == id ) {
							$(this).slideDown(500, function() {
								contentItems.each( function(i) {
									if ( $(this).attr('id') != jQuery.fn.tabs.activeId ) {
										$(this).slideUp(300);
									}
								});
							});
							$(tabItems[i]).addClass('active');
							activeTab = id;
						} else {
							$(this).hide();
							$(tabItems[i]).removeClass('active');
						};
					});
				};
				init();
			});
		}
	});












/*
 * jqDock jQuery plugin
 * Version : 1.1
 * Author : Roger Barrett
 * Date : March 2008
 *
 * Inspired by:
 *   iconDock jQuery plugin
 *   http://icon.cat/software/iconDock
 *   version: 0.8 beta
 *   date: 2/05/2007
 *   Copyright (c) 2007 Isaac Roca & icon.cat (iroca@icon.cat)
 *   Dual licensed under the MIT-LICENSE.txt and GPL-LICENSE.txt
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Dual licensed under the MIT-LICENSE.txt and GPL-LICENSE.txt
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

;(function($){if(!$.fn.jqDock){var jqDock=function(){return{version:1.1,defaults:{size:36,distance:54,coefficient:1.5,duration:500,align:'bottom',labels:false,source:false,loader:null},useJqLoader:$.browser.opera||$.browser.safari,shrinkInterval:100,docks:[],X:0,Y:0,verthorz:{v:{wh:'height',xy:'Y',tl:'top',lead:'Top',trail:'Bottom',act:'ActualInv'},h:{wh:'width',xy:'X',tl:'left',lead:'Left',trail:'Right',act:'Actual'}},elementCss:{position:'relative',borderWidth:0,borderStyle:'none',verticalAlign:'top'},vanillaDiv:'<div style="position:relative;margin:0px;padding:0px;border:0px none;background-color:transparent;">',initDock:function(id){var ME=this,Dock=this.docks[id],op=Dock.Opts,off=0,AI=$('a, img',Dock.Menu),i=0,j,el,wh,acc,upad;this.removeText(Dock.Menu);if(op.orient.vh=='h'){if($.browser.opera||!$.boxModel){AI.css(this.elementCss).filter('a').css({lineHeight:0,fontSize:'0px'})}else{var hcss={display:'block'};hcss['float']='left';AI.css(this.elementCss).filter('img').css(hcss)}}else{AI.not($('a img',Dock.Menu)).wrap(this.vanillaDiv+'</div>').end().css(this.elementCss)}while(i<Dock.Elem.length){el=Dock.Elem[i++];wh=this.keepProportion(el,op.size,{vh:op.orient.inv,inv:op.orient.vh});el.Actual=el.Final=el.Initial=wh[op.vh.wh];el.SizeDiff=el[op.vh.wh]-el.Initial;el.Img.css(wh);el.Img.removeAttr('title').attr({alt:''}).parent('a').removeAttr('title');el.ShrinkStep=Math.floor(el.SizeDiff*this.shrinkInterval/op.duration);Dock[op.vh.inv.wh]=Math.max(Dock[op.vh.inv.wh],op.size+el.Pad[op.vh.inv.lead]+el.Pad[op.vh.inv.trail]);el.Offset=off;el.Centre=el.Offset+el.Pad[op.vh.lead]+(el.Initial/2);off+=el.Initial+el.Pad[op.vh.lead]+el.Pad[op.vh.trail]}i=0;while(i<Dock.Elem.length){el=Dock.Elem[i++];acc=0;upad=el.Pad[op.vh.lead]+el.Pad[op.vh.trail];Dock.Spread+=el.Initial+upad;this.setSizes(id,el.Centre);j=Dock.Elem.length;while(j){acc+=Dock.Elem[--j].Final+upad}Dock[op.vh.wh]=Math.max(Dock[op.vh.wh],acc)}while(i){el=Dock.Elem[--i];el.Final=el.Initial}var wrap=[this.vanillaDiv,'<div class="jqDock" style="position:absolute;top:0px;left:0px;padding:0px;','margin:0px;overflow:visible;height:',Dock.height,'px;width:',Dock.width,'px;"></div></div>'].join('');Dock.Yard=$(Dock.Menu).wrapInner(wrap).find('div.jqDock');$.each([op.vh.lead,op.vh.trail],function(n,v){Dock.Borders[v]=ME.asNumber(Dock.Yard.css('border'+v+'Width'))});if(Dock.Borders[op.vh.lead]){Dock.Yard.css(op.vh.tl,Math.ceil(Dock.Borders[op.vh.lead]/2))}while(i<Dock.Elem.length){el=Dock.Elem[i];this.changeSize(id,i,el.Final,true);el.Img.addClass('jqDockMouse'+id+'_'+(i++))}$(Dock.Menu).show();if(Dock.Opts.labels){$.each(Dock.Elem,function(i){ME.setLabel(id,this.Label)});Dock.Label.hide()}Dock.Yard.bind('mouseover mouseout mousemove',function(e){ME.mouseHandler(e)})},altImage:function(){var alt=$(this).attr('alt');return(alt&&alt.match(/\.(gif|jpg|jpeg|png)$/i))?alt:false},removeText:function(el){var i=el.childNodes.length,j;while(i){j=el.childNodes[--i];if(j.childNodes&&j.childNodes.length){this.removeText(j)}else if(j.nodeType==3){el.removeChild(j)}}},asNumber:function(x){var r=parseInt(x,10);return isNaN(r)?0:r},keepProportion:function(el,dim,orient){var r={},vh=this.verthorz[orient.vh],inv=this.verthorz[orient.inv];r[vh.wh]=dim;r[inv.wh]=Math.round(dim*el[inv.wh]/el[vh.wh]);return r},deltaXY:function(id){var Dock=this.docks[id];if(Dock.Current!==false){var op=Dock.Opts,el=Dock.Elem[Dock.Current],p=el.Pad[op.vh.lead]+el.Pad[op.vh.trail],off=el.Img.offset();Dock.Delta=Math.floor((this[op.vh.xy]-off[op.vh.tl])*(p+el.Initial)/(p+el.Actual))+el.Offset;this.doLabel(id,off)}},setLabel:function(id,label){var Dock=this.docks[id],ME=this,pad={};if(!Dock.Label){Dock.Label=$('<div class="jqDockLabel jqDockMouse'+id+'_00 jqDockLabelImage" style="position:absolute;margin:0px;"></div>').hide().bind('click',function(){Dock.Elem[Dock.Current].Img.trigger('click')}).appendTo(Dock.Yard)}if(label.txt){Dock.Label.text(label.txt);$.each(['Top','Right','Bottom','Left'],function(n,v){pad[v]=ME.asNumber(Dock.Label.css('padding'+v))});$.each(this.verthorz,function(vh,o){label[o.wh]=Dock.Label[o.wh]();label[o.wh+'Pad']=pad[o.lead]+pad[o.trail]})}},doLabel:function(id,off){var Dock=this.docks[id];if(Dock.Opts.labels&&Dock.Current!==false){var el=Dock.Elem[Dock.Current],L=el.Label,op=Dock.Opts,what=typeof off=='string'?off:'move';switch(what){case'show':case'hide':Dock.Label[L.txt?what:'hide']();break;case'change':Dock.Label[0].className=Dock.Label[0].className.replace(/(jqDockLabel)(Link|Image)/,'$1'+(el.Linked?'Link':'Image'));Dock.Label.html('<span>'+L.txt+'</span>').css({width:L.width,height:L.height}).hide();break;default:var doff=Dock.Yard.offset(),css={top:off.top-doff.top,left:off.left-doff.left},splt=op.labels.split('');if(splt[0]=='m'){css.top+=Math.floor((el[op.vh.inv.act]-L.height-L.heightPad)/2)}else if(splt[0]=='b'){css.top+=el[op.vh.inv.act]+el.Pad.Top+el.Pad.Bottom-L.height-L.heightPad}if(splt[1]=='c'){css.left+=Math.floor((el[op.vh.act]-L.width-L.widthPad)/2)}else if(splt[1]=='r'){css.left+=el[op.vh.act]+el.Pad.Left+el.Pad.Right-L.width-L.widthPad}css.top+=30;css.left+=20;Dock.Label.css(css)}}},mouseHandler:function(e){var r=null,t=e.target.className.match(/jqDockMouse(\d+)_(\d+)/),rt=!!(e.relatedTarget)&&e.relatedTarget.tagName!==undefined;if(t){r=false;var id=1*t[1],Dock=this.docks[id],idx=t[2]=='00'?Dock.Current:1*t[2];this.X=e.pageX;this.Y=e.pageY;if(e.type=='mousemove'){if(idx==Dock.Current){this.deltaXY(id);if(Dock.OnDock&&Dock.Expanded){this.setSizes(id);this.factorSizes(id)}}}else{var rel=rt&&e.relatedTarget.className.match(/jqDockMouse(\d+)_(\d+)/);if(e.type=='mouseover'&&(!Dock.OnDock||idx!==Dock.Current)){Dock.Current=idx;this.doLabel(id,'change');this.deltaXY(id);if(Dock.Expanded){this.doLabel(id,'show')}if(rt&&(!rel||rel[1]!=id)){Dock.Timestamp=(new Date()).getTime();this.setSizes(id);Dock.OnDock=true;this.overDock(id)}}else if(rt&&e.type=='mouseout'){if(!rel||rel[1]!=id){Dock.OnDock=false;this.doLabel(id,'hide');var i=Dock.Elem.length;while((i--)){Dock.Elem[i].Final=Dock.Elem[i].Intial}this.offDock(id)}}}}return r},overDock:function(id){var Dock=this.docks[id];if(Dock.OnDock){var ME=this,el=Dock.Elem,i=el.length;while((i--)&&!(el[i].Actual<el[i].Final)){}if(i<0){Dock.Expanded=true;this.deltaXY(id);this.doLabel(id,'show')}else{this.setSizes(id);this.factorSizes(id);setTimeout(function(){ME.overDock(id)},60)}}},offDock:function(id){var Dock=this.docks[id];if(!Dock.OnDock){var ME=this,done=true,i=Dock.Elem.length,el,sz;while(i){el=Dock.Elem[--i];if(el.Actual>el.Initial){sz=el.Actual-el.ShrinkStep;if(sz>el.Initial){done=false}else{sz=el.Initial}this.changeSize(id,i,sz)}}this.deltaXY(id);if(done){while(i<Dock.Elem.length){el=Dock.Elem[i++];el.Actual=el.Final=el.Initial}Dock.Current=Dock.Expanded=false}else{setTimeout(function(){ME.offDock(id)},this.shrinkInterval)}}},setSizes:function(id,mxy){var Dock=this.docks[id],op=Dock.Opts,i=Dock.Elem.length,el,sz;mxy=mxy||Dock.Delta;while(i){el=Dock.Elem[--i];sz=Math.floor(el.SizeDiff*Math.pow(Math.abs(mxy-el.Centre),op.coefficient)/op.attenuation);el.Final=(sz<el.SizeDiff?el[op.vh.wh]-sz:el.Initial)}},factorSizes:function(id){var Dock=this.docks[id],op=Dock.Opts,lapse=op.duration+60;if(Dock.Timestamp){lapse=(new Date()).getTime()-Dock.Timestamp;if(lapse>=op.duration){Dock.Timestamp=0}}if(lapse>60){var f=lapse<op.duration?lapse/op.duration:0,i=0,el;while(i<Dock.Elem.length){el=Dock.Elem[i];this.changeSize(id,i++,(f?Math.floor(el.Initial+((el.Final-el.Initial)*f)):el.Final))}}},changeSize:function(id,idx,dim,force){var Dock=this.docks[id],el=Dock.Elem[idx];if(force||el.Actual!=dim){var op=Dock.Opts,bdr=($.boxModel||op.orient.vh=='v')?0:Dock.Borders[op.vh.lead]+Dock.Borders[op.vh.trail];if(el.Source[2]&&!force&&el.Actual==el.Initial){el.Img[0].src=el.Source[1]}if(Dock.OnDock){this.deltaXY(id)}Dock.Spread+=dim-el.Actual;var css=this.keepProportion(el,dim,op.orient),diff=op.size-css[op.vh.inv.wh],m='margin',z=op.vh.inv;switch(op.align){case'bottom':case'right':css[m+z.lead]=diff;break;case'middle':case'center':css[m+z.lead]=(diff+diff%2)/2;css[m+z.trail]=(diff-diff%2)/2;break;case'top':case'left':css[m+z.trail]=diff;break;default:}Dock.Yard[op.vh.wh](Dock.Spread+bdr);el.Img.css(css);Dock.Yard.css('margin'+op.vh.lead,Math.floor((Dock[op.vh.wh]-Dock.Spread)/2));el.Actual=dim;el.ActualInv=css[op.vh.inv.wh];if(el.Source[2]&&!force&&el.Actual==el.Initial){el.Img[0].src=el.Source[0]}}}}}();$.fn.jqDock=function(opts){return this.filter(function(){var i=jqDock.docks.length;while((i--)&&this!=jqDock.docks[i].Menu){}return(i<0)&&($('img',this).length)}).hide().each(function(){var id=jqDock.docks.length;jqDock.docks[id]={Elem:[],Menu:this,OnDock:false,Expanded:false,Timestamp:0,width:0,height:0,Spread:0,Borders:{},Yard:false,Opts:$.extend({},jqDock.defaults,opts||{}),Current:false,Delta:0,Loaded:0,Label:false};var Dock=jqDock.docks[id],op=Dock.Opts;op.attenuation=Math.pow(op.distance,op.coefficient);op.orient=({left:1,center:1,right:1}[op.align])?{vh:'v',inv:'h'}:{vh:'h',inv:'v'};op.vh=$.extend({},jqDock.verthorz[op.orient.vh],{inv:jqDock.verthorz[op.orient.inv]});op.loader=(op.loader)&&typeof op.loader=='string'&&/^image|jquery$/i.test(op.loader)?op.loader.toLowerCase():'';op.labels=op.labels===true?{top:'bc',left:'tr',right:'tl'}[op.align]||'tc':(typeof op.labels=='string'&&{tl:1,tc:1,tr:1,ml:1,mc:1,mr:1,bl:1,bc:1,br:1}[op.labels]?op.labels:false);$('img',this).each(function(n){var me=$(this),s0=me.attr('src'),s1=(op.source?op.source.call(me[0],n):false)||jqDock.altImage.call(this)||s0,tx=op.labels?me.attr('title')||me.parent('a').attr('title')||'':'';Dock.Elem[n]={Img:me,Source:[s0,s1,!(s0==s1)],Label:{txt:tx,width:0,height:0,widthPad:0,heightPad:0},Initial:0,Actual:0,ActualInv:0,Final:0,Offset:0,Centre:0,Pad:{},Linked:!!me.parent('a').length,width:0,height:0};$.each(['Top','Right','Bottom','Left'],function(i,v){Dock.Elem[n].Pad[v]=jqDock.asNumber(me.css('padding'+v))})});var jqld=(!op.loader&&jqDock.useJqLoader)||op.loader=='jquery';$.each(Dock.Elem,function(i){var me=this,iLoaded=function(){me.height=this.height;me.width=this.width;if(++Dock.Loaded>=Dock.Elem.length){setTimeout(function(){jqDock.initDock(id)},0)}};if(jqld){$('<img />').bind('load',iLoaded).attr({src:this.Source[1]})}else{var pre=new Image();pre.onload=function(){iLoaded.call(this);pre.onload=function(){}};pre.src=this.Source[1]}})}).end()};$.jqDock=function(x){return jqDock[x]?jqDock[x]:null}}})(jQuery);