/* jQuery.ScrollTo - Easy element scrolling using jQuery. Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com Dual licensed under MIT and GPL. @author Ariel Flesler @version 1.4.2 http://flesler.blogspot.com/2007/10/jqueryscrollto.html */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/* jQuery Shuffle Plugin */
(function($){$.fn.shuffle=function(){return this.each(function(){var items=$(this).children().clone(true);return(items.length)?$(this).html($.shuffle(items)):this;});}
$.shuffle=function(arr){for(var j,x,i=arr.length;i;j=parseInt(Math.random()*i),x=arr[--i],arr[i]=arr[j],arr[j]=x);return arr;}})(jQuery);

/* jQuery infinitecarousel plugin * @author admin@catchmyfame.com - http://www.catchmyfame.com * @version 1.2.2 */
(function($){$.fn.extend({infiniteCarousel:function(options)
{var defaults={transitionSpeed:1500,displayTime:6000,textholderHeight:.2,displayProgressBar:1,displayThumbnails:1,displayThumbnailNumbers:1,displayThumbnailBackground:1,thumbnailWidth:'20px',thumbnailHeight:'20px',thumbnailFontSize:'.7em'};var options=$.extend(defaults,options);return this.each(function(){var randID=Math.round(Math.random()*100000000);var o=options;var obj=$(this);var curr=1;var numImages=$('img',obj).length;var imgHeight=$('img:first',obj).height();var imgWidth=$('img:first',obj).width();var autopilot=1;$('p',obj).hide();$(obj).width(imgWidth).height(imgHeight);if(o.displayProgressBar)
{$(obj).append('<div id="progress'+randID+'" style="position:absolute;bottom:0;background:#000;z-index:100;left:'+$(obj).css('paddingLeft')+'"></div>');$('#progress'+randID).width('100%').height(5).css('opacity','.5');}
$(obj).css({'overflow':'hidden','position':'relative'});$('li:last',obj).prependTo($('ul',obj));$('ul',obj).css('left',-imgWidth+'px');$('ul',obj).width(9999);$('ul',obj).css({'list-style':'none','margin':'0','padding':'0','position':'relative'});$('li',obj).css({'display':'inline','float':'left'});$(obj).append('<div id="textholder'+randID+'" class="textholder" style="position:absolute;bottom:0px;margin-bottom:'+-imgHeight*o.textholderHeight+'px;left:'+$(obj).css('paddingLeft')+'"></div>');var correctTHWidth=parseInt($('#textholder'+randID).css('paddingTop'));var correctTHHeight=parseInt($('#textholder'+randID).css('paddingRight'));$('#textholder'+randID).width(imgWidth-(correctTHWidth*2)).height((imgHeight*o.textholderHeight)-(correctTHHeight*2)).css({'backgroundColor':'#FFF','opacity':'0.5'});showtext($('li:eq(1) p',obj).html());html='<div id="btn_rt'+randID+'" style="position:absolute;right:-33px;z-index:500;top:'+((imgHeight/2)-53)+'px"><a href="javascript:void(0);"><img style="border:none;" src="wp-content/themes/vp/images/rt.png" /></a></div>';html+='<div id="btn_lt'+randID+'" style="position:absolute;z-index:500;left:-33px;top:'+((imgHeight/2)-53)+'px"><a href="javascript:void(0);"><img style="border:none;" src="wp-content/themes/vp/images/lt.png" /></a></div>';$('#gallery_wrapper').append(html);html='<a href="javascript:void(0);"><img id="pause_btn'+randID+'" src="wp-content/themes/vp/images/pause.png" style="z-index:500;position:absolute;top:3px;right:3px;border:none" alt="Pause" /></a>';html+='<a href="javascript:void(0);"><img id="play_btn'+randID+'" src="wp-content/themes/vp/images/play.png" style="z-index:500;position:absolute;top:3px;right:3px;border:none;display:none;" alt="Play" /></a>';$('#gallery_wrapper').append(html);$('#pause_btn'+randID).css('opacity','.5').hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'.5'},250)});$('#pause_btn'+randID).click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();clearTimeout(clearInt);$('#pause_btn'+randID).fadeOut(250);$('#play_btn'+randID).fadeIn(250);showminmax();});$('#play_btn'+randID).css('opacity','.5').hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'.5'},250)});$('#play_btn'+randID).click(function(){autopilot=1;anim('next');$('#play_btn'+randID).hide();clearInt=setInterval(function(){anim('next');},o.displayTime+o.transitionSpeed);setTimeout(function(){$('#pause_btn'+randID).show();$('#progress'+randID).fadeIn().width('100%').height(5);},o.transitionSpeed);});$('#btn_rt'+randID).css('opacity','1').click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();anim('next');setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);clearTimeout(clearInt);}).hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'.75'},250)});$('#btn_lt'+randID).css('opacity','1').click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();anim('prev');setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);clearTimeout(clearInt);}).hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'1'},250)});if(o.displayThumbnails)
{$(obj).append('<div id="thumbs'+randID+'" style="position:relative;overflow:auto;text-align:left;padding-top:5px;"></div>');$('#thumbs'+randID).width(imgWidth);for(i=0;i<=numImages-1;i++)
{thumb=$('img:eq('+(i+1)+')',obj).attr('src');$('#thumbs'+randID).append('<div class="thumb" id="thumb'+randID+'_'+(i+1)+'" style="cursor:pointer;background-image:url('+thumb+');display:inline;float:left;width:'+o.thumbnailWidth+';height:'+o.thumbnailHeight+';line-height:'+o.thumbnailHeight+';padding:0;overflow:hidden;text-align:center;border:2px solid #ccc;margin-right:4px;font-size:'+o.thumbnailFontSize+';font-family:Arial;color:#000;text-shadow:0 0 3px #fff">'+(i+1)+'</div>');if(i==0)$('#thumb'+randID+'_1').css({'border-color':'#ff0000'});}
thumb=$('img:first',obj).attr('src');$('#thumb'+randID+'_'+numImages).css({'background-image':'url('+thumb+')'});$('#thumbs'+randID+' div.thumb:not(:first)').css({'opacity':'.65'});$('#thumbs'+randID+' div.thumb').hover(function(){$(this).animate({'opacity':.99},150)},function(){if(curr!=this.id.split('_')[1])$(this).animate({'opacity':.65},250)});$('#thumbs'+randID+' div').bind('click',thumbclick);if(!o.displayThumbnailNumbers)$('#thumbs'+randID+' div').text('');if(!o.displayThumbnailBackground)$('#thumbs'+randID+' div').css({'background-image':'none'});}
function thumbclick(event)
{target_num=this.id.split('_');if(curr!=target_num[1])
{$('#thumb'+randID+'_'+curr).css({'border-color':'#ccc'});$('#progress'+randID).stop().fadeOut();clearTimeout(clearInt);$('#thumbs'+randID+' div').css({'cursor':'default'}).unbind('click');autopilot=0;setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);}
if(target_num[1]>curr)
{diff=target_num[1]-curr;anim('next',diff);}
if(target_num[1]<curr)
{diff=curr-target_num[1];anim('prev',diff);}}
function showtext(t)
{if(t!=null)
{$('#textholder'+randID).html(t).animate({marginBottom:'0px'},500);showminmax();}}
function showminmax()
{if(!autopilot)
{html='<img style="position:absolute;top:2px;right:18px;display:none;cursor:pointer" src="wp-content/themes/vp/images/down.png" title="Minimize" alt="minimize" id="min" /><img style="position:absolute;top:2px;right:18px;display:none;cursor:pointer" src="wp-content/themes/vp/images/up.png" title="Maximize" alt="maximize" id="max" />';html+='<img style="position:absolute;top:2px;right:6px;display:none;cursor:pointer" src="wp-content/themes/vp/images/close.png" title="Close" alt="close" id="close" />';$('#textholder'+randID).append(html);$('#min').fadeIn(250).click(function(){$('#textholder'+randID).animate({marginBottom:(-imgHeight*o.textholderHeight)-(correctTHHeight*2)+24+'px'},500,function(){$("#min,#max").toggle();});});$('#max').click(function(){$('#textholder'+randID).animate({marginBottom:'0px'},500,function(){$("#min,#max").toggle();});});$('#close').fadeIn(250).click(function(){$('#textholder'+randID).animate({marginBottom:(-imgHeight*o.textholderHeight)-(correctTHHeight*2)+'px'},500);});}}
function borderpatrol(elem)
{$('#thumbs'+randID+' div').css({'border-color':'#ccc'}).animate({opacity:0.65},500);setTimeout(function(){elem.css({'border-color':'#ff0000'}).animate({'opacity':.99},500);},o.transitionSpeed);}
function anim(direction,dist)
{$('#btn_rt'+randID).fadeOut(500);$('#btn_lt'+randID).fadeOut(500);$('#textholder'+randID).animate({marginBottom:(-imgHeight*o.textholderHeight)-(correctTHHeight*2)+'px'},500);$('#pause_btn'+randID).fadeOut(250);$('#play_btn'+randID).fadeOut(250);if(direction=="next")
{if(curr==numImages)curr=0;if(dist>1)
{borderpatrol($('#thumb'+randID+'_'+(curr+dist)));$('li:lt(2)',obj).clone().insertAfter($('li:last',obj));$('ul',obj).animate({left:-imgWidth*(dist+1)},o.transitionSpeed,function(){$('li:lt(2)',obj).remove();for(j=1;j<=dist-2;j++)
{$('li:first',obj).clone().insertAfter($('li:last',obj));$('li:first',obj).remove();}
$('#btn_rt'+randID).fadeIn(500);$('#btn_lt'+randID).fadeIn(500);$('#play_btn'+randID).fadeIn(250);showtext($('li:eq(1) p',obj).html());$(this).css({'left':-imgWidth});curr=curr+dist;$('#thumbs'+randID+' div').bind('click',thumbclick).css({'cursor':'pointer'});});}
else
{borderpatrol($('#thumb'+randID+'_'+(curr+1)));$('#thumbs'+randID+' div').css({'cursor':'default'}).unbind('click');$('li:first',obj).clone().insertAfter($('li:last',obj));$('ul',obj).animate({left:-imgWidth*2},o.transitionSpeed,function(){$('li:first',obj).remove();$('ul',obj).css('left',-imgWidth+'px');$('#btn_rt'+randID).fadeIn(500);$('#btn_lt'+randID).fadeIn(500);if(autopilot)$('#pause_btn'+randID).fadeIn(250);showtext($('li:eq(1) p',obj).html());if(autopilot)
{$('#progress'+randID).width('100%').height(5);$('#progress'+randID).animate({'width':0},o.displayTime,function(){$('#pause_btn'+randID).fadeOut(50);setTimeout(function(){$('#pause_btn'+randID).fadeIn(250)},o.transitionSpeed)});}
curr=curr+1;$('#thumbs'+randID+' div').bind('click',thumbclick).css({'cursor':'pointer'});});}}
if(direction=="prev")
{if(dist>1)
{borderpatrol($('#thumb'+randID+'_'+(curr-dist)));$('li:gt('+(numImages-(dist+1))+')',obj).clone().insertBefore($('li:first',obj));$('ul',obj).css({'left':(-imgWidth*(dist+1))}).animate({left:-imgWidth},o.transitionSpeed,function(){$('li:gt('+(numImages-1)+')',obj).remove();$('#btn_rt'+randID).fadeIn(500);$('#btn_lt'+randID).fadeIn(500);$('#play_btn'+randID).fadeIn(250);showtext($('li:eq(1) p',obj).html());curr=curr-dist;$('#thumbs'+randID+' div').bind('click',thumbclick).css({'cursor':'pointer'});});}
else
{borderpatrol($('#thumb'+randID+'_'+(curr-1)));$('#thumbs'+randID+' div').css({'cursor':'default'}).unbind('click');$('li:last',obj).clone().insertBefore($('li:first',obj));$('ul',obj).css('left',-imgWidth*2+'px').animate({left:-imgWidth},o.transitionSpeed,function(){$('li:last',obj).remove();$('#btn_rt'+randID).fadeIn(500);$('#btn_lt'+randID).fadeIn(500);if(autopilot)$('#pause_btn'+randID).fadeIn(250);showtext($('li:eq(1) p',obj).html());curr=curr-1;if(curr==0)curr=numImages;$('#thumbs'+randID+' div').bind('click',thumbclick).css({'cursor':'pointer'});});}}}
var clearInt=setInterval(function(){anim('next');},o.displayTime+o.transitionSpeed);$('#progress'+randID).animate({'width':0},o.displayTime+o.transitionSpeed,function(){$('#pause_btn'+randID).fadeOut(100);setTimeout(function(){$('#pause_btn'+randID).fadeIn(250)},o.transitionSpeed)});});}});})(jQuery);

/* Adapted from jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ Open source under the BSD License. Copyright å© 2008 George McGinley Smith  All rights reserved. */
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	}
}); //end jQuery Easing Plugin

/**
 * Equal Heights Plugin
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","hidden");
		});
	}
})(jQuery);
//End Equal Heights Plugin

$(function() {
	$('#gallery_ul').shuffle();
//	$('#gallery_ul').load('http://minimalpixel.com/dev/vp/wp-content/themes/vp/gallery_items.php li');	
	
	$('#gallery').infiniteCarousel({
		transitionSpeed : 2000,
		displayTime : 9000,
		displayThumbnails : 0,
		displayProgressBar : 1
	});
});


$(document).ready(function(){

	//Nav Scroll Magic
	$('#nav_home, #nav_home_f').click(function(){
		$.scrollTo( '#home', 1000, { easing: 'easeInOutQuart', offset:{ top:-148,left:0 } });
		return false;
	});
	$('#nav_about, #nav_about_f').click(function(){
		$.scrollTo( '#about', 1000, { easing: 'easeInOutQuart', offset:{ top:-148,left:0 } });
		return false;
	});
	$('#nav_investment, #nav_investment_f').click(function(){
		$.scrollTo( '#investment', 1000, { easing: 'easeInOutQuart', offset:{ top:-148,left:0 } });
		return false;
	});
	$('#testimonial_link').click(function() {
		$.scrollTo( '#testimonials', 1000, { easing: 'easeInOutQuart', offset:{ top: -148,left:0 } });
		return false;
	});

	//Hide/Show Search form
	$('#search_button').show(); //Only show the icon if JS is enabled
	$('#search_button').click(function() {
		$('#search_container').slideToggle();
	});

	var testimonials = $('#testimonials div.testimony');
	testimonials.css('float', 'left');
	testimonials.css('position', 'relative');
	testimonials.children().css('float', 'none');
	//testimonials.css('border', '1px solid #ff0000');
	
	//Testimonial Hover Effect
	testimonials.hover(
		function(event){
			event.stopPropagation();
			$(this).siblings('div.testimony').stop(true).fadeTo('slow', '0.8');
		}, function(event){
			event.stopPropagation();
			$(this).siblings().stop(true).fadeTo('fast', '1');
		}
	);
	
	$('.price_column').equalHeights();
	
	$('.post_list_meta a[rel="category tag"]').wrapInner('<span class="category" />');
	$('.post_list_meta .category').unwrap();

});

Cufon.replace('.classy');

	$('#testimonials_readmore').live('click', function() {
		$('#testimonials').animate({
			height: '1600px'
		}, 2000, function() {
			$('#testimonials_readmore').replaceWith('<a id="testimonials_readless" title="Read Less Testimonials">Read Less</a>');
		});
	});
	$('#testimonials_readless').live('click', function() {
		$('#testimonials').animate({
			height: '680px'
		}, 2000, function() {
			$('#testimonials_readless').replaceWith('<a id="testimonials_readmore" title="Read More">Read More</a>');
		});
	});
