jQuery('html').removeClass('no-js');


/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

var $j = jQuery.noConflict();


var timerId;

function now() {
    return (new Date).getTime();
}

jQuery.fx.prototype.custom = function( from, to, unit ) {
    this.startTime = now();
    this.start = from;
    this.end = to;
    this.unit = unit || this.unit || "px";
    this.now = this.start;
    this.pos = this.state = 0;

    var self = this;
    function t( gotoEnd ) {
        return self.step(gotoEnd);
    }

    t.elem = this.elem;

        if ( t() && jQuery.timers.push(t) && !timerId ) {
    timerId = setInterval(function(){
        var timers = jQuery.timers;

        for ( var i = 0; i < timers.length; i++ )
            if ( !timers[i]() )
                timers.splice(i--, 1);

        if ( !timers.length ) {
            clearInterval( timerId );
            timerId = undefined;
        }
    }, 1);
}
};

/**
 * 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
 *
 */
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;
    }
};



(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		blue:[220,207,178],
		blue2:[210,200,170],
		blue3:[230,217,188],
		blue4:[220,190,160],
		blue5:[220,207,178],
		jcolors:[18,34,47],
		jcolors2:[14,28,40],
		jcolors3:[20,39,55]
	};
	
})(jQuery);


/*
	Sliding Labels 3.2
	
	This is the official plugin version of Sliding Labels.
	It is open source code by Tim Wright of CSSKarma.com
	Use as you see fit, I'd like it if you kept this in 
	the code, but basically share it and don't be a jerk.
	
	Support:
	http://www.csskarma.com/blog/sliding-labels-plugin
	
	Version: 2 - added textarea functionality
	Version: 3 - added axis parameter
	           - added speed parameter
	           - removed color parameter, as it should be define in the CSS
	           - added position:relative to wrapping element
	           - coverted to jQuery plugin
	Version: 3.1 - changed "children" to "find" so it works a little better with UL & fieldsets
	Version: 3.2 - Added a "className" option so you don't have to use ".slider" as the wrapper
*/

(function($j){$j.fn.slidinglabels=function(options){var defaults={className:"slider",topPosition:"5px",leftPosition:"5px",axis:"x",speed:"fast"};var options=$j.extend(defaults,options);var itemwrapper=this.find("."+defaults.className+"");var labels=itemwrapper.find("label");return labels.each(function(){obj=$j(this);var parent=obj.parents("."+defaults.className+"");parent.css({position:"relative"});obj.css({position:"absolute",top:defaults.topPosition,left:defaults.leftPosition,display:"inline","z-index":99});var inputval=$j(this).next().val();var labelwidth=$j(this).width();var labelmove=labelwidth+5+"px";var labelheight=$j(this).height();if(inputval!==""){if(defaults.axis=="x"){obj.stop().animate({left:"-"+labelmove},1)}else{if(defaults.axis=="y"){obj.stop().animate({top:"-"+labelheight},1)}}}$j("input, textarea").focus(function(){var label=$j(this).prev("label");var width=label.width();var height=label.height();var adjust=width+5+"px";var adjustUp=height+"px";var value=$j(this).val();if(value==""){if(defaults.axis=="x"){label.stop().animate({left:"-"+adjust},defaults.speed)}else{if(defaults.axis=="y"){label.stop().animate({top:"-"+adjustUp},defaults.speed)}}}else{if(defaults.axis=="x"){label.css({left:"-"+adjust})}else{if(defaults.axis=="y"){label.css({top:"-"+adjustUp})}}}}).blur(function(){var label=$j(this).prev("label");var value=$j(this).val();if(value==""){if(defaults.axis=="x"){label.stop().animate({left:defaults.leftPosition},defaults.speed)}else{if(defaults.axis=="y"){label.stop().animate({top:defaults.topPosition},defaults.speed)}}}})})}})(jQuery);




$j(function(){

// Search Form
$j('#searchform').children('div').prepend('<span class="end"></span>'); 
$j('p.comment-form-author, p.comment-form-email, p.comment-form-url').prepend('<span class="end"></span>'); 
var searchWidth = $j('input#s').width();
$j('input#s').css({'width': (searchWidth - 19)});
$j(window).resize(function() {
var searchWidth = $j('#searchform div').width();
$j('input#s').css({'width': (searchWidth - 19)});
});


function smoothScroll() {

 $j('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $jtarget = $j(this.hash);
            
            $jtarget = $jtarget.length && $jtarget || $j('[name=' + this.hash.slice(1) +']');
            
            if ($jtarget.length) {
            
                var targetOffset = $jtarget.offset().top;
                
                $j('html,body').animate({scrollTop: targetOffset}, 1000);
                    
                return false;
                
            }
            
        }
        
    });
} // smoothScroll


smoothScroll();


var goldenRatio = $j('.slideshow').width();
var initialHeight = (goldenRatio / 100) * 62.74285714285714; 
$j('.slide img').css({'height': initialHeight});

// Reset the Portfolio Slideshow
$j(window).resize(function() {
// Set the image width to the width of the right column
var goldenRatio = $j('.slideshow').width();
// Get the height of the image to size the slidecontainer correctly
var goldenHeight = $j('.slide img').height();
$j('.slide img').css({'width': goldenRatio});
var initialHeight = (goldenRatio / 100) * 62.74285714285714; 
$j('.slide img').css({'height': initialHeight});
portfolioSlide();
var goldenRatio = $j('.slideshow').width();
var slideWidth = $j('.slide img').width();
var slideHeight = $j('.slide img').height();
$j('.slidescontainer').css({'height': goldenHeight});
$j('.slideshow').css({'height': goldenHeight});
$j('.slide').css({'width': goldenRatio});

});

// Portfolio Slideshow


$j('.slideshow')
    .prepend('<span class="control leftControl">Move left</span>')
    .append('<span class="control rightControl">Move right</span>');
    controlsInit();
var slideWidth = $j('.slide img').width();
var slideHeight = $j('.slide img').height();

var goldenHeight = $j('.slide img').height();
portfolioSlide();



function portfolioSlide() {
$j('.slideshow').each(function(){
var slideshow = $j(this);
var currentPosition = 0;

var portfolioGalleryHeight = slideHeight;
var slides = slideshow.children('.slidescontainer').children('.slide');
var numberOfSlides = slides.length;
var slidescontainer = slideshow.children('.slidescontainer');

slideshow.css({'height': portfolioGalleryHeight});
slidescontainer.css({'overflow': 'hidden', 'height': slideHeight});
slides.wrapAll('<div class="slideInner"></div>');
// Float left to display horizontally, readjust .slides width
slides.css({
'float' : 'left',
'width' : slideWidth
});
slides.parent('.slideInner').css({'float' : 'left','width': slideWidth * numberOfSlides});
  // $j('.portfolio-slide img').css({'width': slideWidth});




});
}




function controlsInit() {
$j('.slideshow').each(function(){
var currentPosition = 0;
var slideshow = $j(this);
var slides = slideshow.children('.slidescontainer').children('.slide');
var numberOfSlides = slides.length;
var slideWidth = $j('.slide img').width();

 manageControls(currentPosition);

slideshow.children('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($j(this).attr('class')=='control rightControl vis')
    ? currentPosition+1 : currentPosition-1;

  manageControls(currentPosition);
 // Move slideInner using margin-left
 
 var imageWidth = $j('.slide img').width();
 $j(window).resize(function() {
 $j('.slideInner').css({'width': goldenRatio * numberOfSlides });
 imageWidth = $j('.slide img').width();
  manageDrift(currentPosition);
 function manageDrift(position){
 if(position==1){ slides.parent('.slideInner').css({'marginLeft': -imageWidth}); }
  if(position==2){ slides.parent('.slideInner').css({'marginLeft': 2*(-imageWidth)}); }
 }
 });
 
      slides.parent('.slideInner').animate({
        'marginLeft' : imageWidth*(-currentPosition)
      });
    });
 function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ slideshow.children('.leftControl').fadeOut('fast').addClass('hidden') }
    else{ slideshow.children('.leftControl').fadeIn('fast').removeClass('hidden').addClass('vis') }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ slideshow.children('.rightControl').fadeOut('fast').addClass('hidden') }
    else{ slideshow.children('.rightControl').fadeIn('fast').removeClass('hidden').addClass('vis') }
    }




});
}




//Animate the Background Colour - just once to preserve CPU!
//$j('#wrapper').animate({'backgroundColor':'blue'}, 1200).animate({'backgroundColor':'blue2'}, 1200).animate({'backgroundColor':'blue3'}, 1200).animate({'backgroundColor':'blue4'}, 1200).animate({'backgroundColor':'blue5'}, 1200);


$j('div#jquery').animate({'backgroundColor':'jcolors2'}, 1600).animate({'backgroundColor':'jcolors'}, 1600).animate({'backgroundColor':'jcolors3'}, 1600).animate({'backgroundColor':'jcolors2'}, 1600).animate({'backgroundColor':'jcolors3'}, 1600);


//Initiate the Portfolio Gallery mouseover
$j('.portfolio-meta').hide();
$j('#portfolio-gallery, .slide').each(function(){
$j(this).hover(function() {
$j(this).children('.portfolio-meta').fadeIn('normal');
}, function() {
$j('.portfolio-meta').fadeOut('normal');
});
});





   $j('a.comment-reply-link').unbind('click');

// Contact Us:
var inputWidth = $j('.form-slider input').width();
$j('.form-slider input').css({'width': (inputWidth - 20)});
$j(window).resize(function() {
var inputWidth = $j('.form-slider').width();
$j('.form-slider input').css({'width': (inputWidth - 20)});
});

$j('#contact-form input, input#s, #commentform input').focus(function() {
$j(this).siblings('span.end').css({'backgroundPosition': '0px -358px'});
});
$j('#contact-form input, input#s, #commentform input').blur(function() {
$j(this).siblings('span.end').css({'backgroundPosition': '0px -281px'});
});

	$j('.wpcf7-form').slidinglabels({
		className    : 'form-slider', // the class you're wrapping the label & input with -> default = slider
		topPosition  : '10px',  // how far down you want each label to start
		leftPosition : '10px',  // how far left you want each label to start
		axis         : 'x',    // can take 'x' or 'y' for slide direction
		speed        : 'fast'  // can take 'fast', 'slow', or a numeric value

	});	
	

/*$j('footer').hover(function(){
$j('#footer-fix').fadeIn();

}, function(){
$j('#footer-fix').fadeOut();
});*/

function fixFooter() {
$j('#footer-fix a').click(function() {
$j('#styled-footer').fadeIn('normal', function() {
$j('#inner-footer').slideUp('normal', function(){
$j('#tear-bottom').css('cursor','pointer');
smoothScroll();
$j.cookie('theFooter', 'styled');
});
});
});
}

fixFooter(); 


$j('#tear-bottom').click(function() {
$j('#tear').fadeIn('normal');
$j('#inner-footer').slideDown('normal', function() {
$j('#styled-footer').fadeOut('normal', function() {
$j('#tear-bottom').css('cursor','default');
$j.cookie('theFooter', 'unstyled');
});
});
});

// COOKIES
    // Footer state
    var theFooter = $j.cookie('theFooter');

    // Set the user's selection for the footer
    if (theFooter == 'styled') {
        $j('#inner-footer').css("display","none");
        $j('#styled-footer').css("display","block");
      };
    if (theFooter != 'styled') {
        $j('#inner-footer').css("display","block");
        $j('#styled-footer').css("display","none");
      };



// New Portfolio
//var minusHeader = ($j(window).height() - $j('#inner-header').height());
//$j('#site-holder, #portfolio-two, #site-holder iframe').css('height',minusHeader);
 

});

 

