

/* this prevents dom flickering, needs to be outside of dom.ready event: */
document.documentElement.className += 'js_active';
/*end dom flickering =) */


// -------------------------------------------------------------------------------------------
// cufon
// -------------------------------------------------------------------------------------------

	Cufon.replace('h1, h2, h3, h4, h5, h6, .sidebar_box_title, .entry_title, .entry_title a, .dropcap', {
			hover: 'true',
			textShadow: '#fff 1px 1px'
		});
	Cufon.replace('.dropcap');
	Cufon.replace('ul#nav', {
			hover: 'true'
		});
	Cufon.replace('#featured_message h2', {
			textShadow: '#fff 1px 1px'
		});


// -------------------------------------------------------------------------------------------
// slider
// -------------------------------------------------------------------------------------------							
							
//nivo slider

$(window).load(function() {
	setTimeout(function(){
		$('.nivoslider').nivoSlider({
			slices: '18',
			effect:'fold',
			animSpeed:1000,
			pauseTime:5000,
			startSlide:0,
			captionOpacity:1,
			directionNav:true,
			controlNav:true,
			keyboardNav:false,
			pauseOnHover:false,
			manualAdvance:true
		});
	}, 0);
});


// -------------------------------------------------------------------------------------------
// navigation moving effect
// -------------------------------------------------------------------------------------------

$(document).ready(function(){

	      $('ul#nav li a').hover(function() {
	        $(this).stop().animate({ paddingLeft: '25px'}, {queue:false, duration: 500, easing: 'easeOutQuint'});
	      }, function() {
	        $(this).stop().animate({ paddingLeft: '12px'}, {queue:false, duration: 500, easing: 'easeOutQuint'});           
	      });
		
});


// -------------------------------------------------------------------------------------------
// menu sidebar moving effect
// -------------------------------------------------------------------------------------------

$(document).ready(function(){

	      $('ul.sidebar_menu li a').hover(function() {
	        $(this).stop().animate({ paddingLeft: '40px', backgroundPosition: 10}, {queue:false, duration: 1000, easing: 'easeOutElastic'});
	      }, function() {
	        $(this).stop().animate({ paddingLeft: '30px', backgroundPosition: 0}, {queue:false, duration: 150, easing: ''});           
	      });
		
});


// -------------------------------------------------------------------------------------------
// image fade effect
// -------------------------------------------------------------------------------------------							
							
$(document).ready(function(){

	      $('.img_lightbox a img, .popular_posts ul li a img').hover(function() {
	        $(this, 'img').stop().animate({ opacity: '.3' }, {queue:false, duration: 800, easing: 'easeOutElastic'});
	      }, function() {
	        $(this, 'img').stop().animate({ opacity: '1' }, {queue:false, duration: 500, easing: ''});           
	      });

		
});


// -------------------------------------------------------------------------------------------
// portfolio item
// -------------------------------------------------------------------------------------------							

	$(document).ready(function () {

		// if the mouse hover the image
		$('.photo').hover(
			function() {
				//display heading and caption
				$(this).children('div:first').stop(false,true).animate({top:0},{duration:500, easing: 'easeOutQuint'});
				$(this).children('div:last').stop(false,true).animate({bottom:0},{duration:500, easing: 'easeOutQuint'});
			},

			function() {
				//hide heading and caption
				$(this).children('div:first').stop(false,true).animate({top:-25},{duration:500, easing: 'easeOutQuint'});
				$(this).children('div:last').stop(false,true).animate({bottom:-25},{duration:500, easing: 'easeOutQuint'});
			}
		);

	});


// -------------------------------------------------------------------------------------------
// forms
// -------------------------------------------------------------------------------------------

//search form [keeping the input value when infocus or outfocus]

$(document).ready(function() {
	$('#search_form input[type="text"]').focus(function() {
	    if (this.value == this.defaultValue){ 
		this.value = '';
			}
			if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#search_form input[type="text"]').blur(function() {
	    if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			}
	});
});


//search form [rotating and moving effect]
  
  
            $('#search_form').hover(
                function(){
                    var $this = $(this);
                    expand($this);
                },
                function(){
                    var $this = $(this);
                    collapse($this);
                }
            );
            function expand($elem){
                var angle = 0;
                var t = setInterval(function () {
                    if(angle == 1440){
                        clearInterval(t);
                        return;
                    }
                    angle += 40;
                    $('.search_button',$elem).stop().animate({rotate: '+=-40deg'}, 0);
                },20);
                $elem.stop().animate({width:'335px'}, 1000)
                .find('#search_form_content').fadeIn(1000,function(){
                    $(this).find('p').stop(true,true).fadeIn(500);
                });
            }
            function collapse($elem){
                var angle = 1440;
                var t = setInterval(function () {
                    if(angle == 0){
                        clearInterval(t);
                        return;
                    }
                    angle -= 40;
                    $('.search_button',$elem).stop().animate({rotate: '+=40deg'}, 0);
                },20);
                $elem.stop().animate({width:'60px'}, 1000)
                .find('#search_form_content').stop(true,true).fadeOut().find('p').stop(true,true).fadeOut();
            }


// -------------------------------------------------------------------------------------------
// go to top
// -------------------------------------------------------------------------------------------							

smoothscroll(); //smooth scrolling

function smoothscroll()
{
	jQuery('a[href*=#]').click(function() {
		
	   var newHash=this.hash;
	   
	   if(newHash != '' && newHash != '#' )
	   {
		   var target=jQuery(this.hash).offset().top,
			   oldLocation=window.location.href.replace(window.location.hash, ''),
			   newLocation=this,
			   duration=1200,
			   easing='easeOutQuint';
		
			
			
			
		   // make sure it's the same location      
		   if(oldLocation+newHash==newLocation)
		   {
		      // animate to target and set the hash to the window.location after the animation
		      jQuery('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
		
		         // add new hash to the browser location
		         window.location.href=newLocation;
		      });
		
		      // cancel default click action
		      return false;
		   }
		
		}
	
	});
}


// -------------------------------------------------------------------------------------------
// blockquotes fading sliding
// -------------------------------------------------------------------------------------------							

$(document).ready(function() {
	
	$('blockquote').quovolver();
	
});


/*
 * jQuery Quovolver v1.0 - http://sandbox.sebnitu.com/jquery/quovolver
 *
 * By Sebastian Nitu - Copyright 2009 - All rights reserved
 * 
 */

(function($) {
	$.fn.quovolver = function(speed, delay) {
		
		/* Sets default values */
		if (!speed) speed = 500;
		if (!delay) delay = 6000;
		
		// If "delay" is less than 4 times the "speed", it will break the effect 
		// If that's the case, make "delay" exactly 4 times "speed"
		var quaSpd = (speed*4);
		if (quaSpd > (delay)) delay = quaSpd;
		
		// Create the variables needed
		var	quote = $(this),
			firstQuo = $(this).filter(':first'),
			lastQuo = $(this).filter(':last'),
			wrapElem = '<div id="quote_wrap"></div>';
		
		// Wrap the quotes
		$(this).wrapAll(wrapElem);
		
		// Hide all the quotes, then show the first
		$(this).hide();
		$(firstQuo).show();
		
		// Set the hight of the wrapper
		$(this).parent().css({height: $(firstQuo).height()});		
		
		// Where the magic happens
		setInterval(function(){
			
			// Set required hight and element in variables for animation
			if($(lastQuo).is(':visible')) {
				var nextElem = $(firstQuo);
				var wrapHeight = $(nextElem).height();
			} else {
				var nextElem = $(quote).filter(':visible').next();
				var wrapHeight = $(nextElem).height();
			}
			
			// Fadeout the quote that is currently visible
			$(quote).filter(':visible').fadeOut(speed);
			
			// Set the wrapper to the hight of the next element, then fade that element in
			setTimeout(function() {
				$(quote).parent().animate({height: wrapHeight}, speed);
			}, speed);
			
			if($(lastQuo).is(':visible')) {
				setTimeout(function() {
					$(firstQuo).fadeIn(speed*2);
				}, speed*2);
				
			} else {
				setTimeout(function() {
					$(nextElem).fadeIn(speed);
				}, speed*2);
			}
			
		}, delay);
	
	};
})(jQuery);





//################# Don't do anything with the coming code




//jquery animate css rotate scale

(function ($) {
    // Monkey patch jQuery 1.3.1+ to add support for setting or animating CSS
    // scale and rotation independently.
    // 2009 Zachary Johnson www.zachstronaut.com
    var rotateUnits = 'deg';
    
    $.fn.rotate = function (val)
    {
        var style = $(this).css('transform') || 'none';
        
        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/rotate\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }
            
            return 0;
        }
        
        var m = val.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/);
        if (m)
        {
            if (m[3])
            {
                rotateUnits = m[3];
            }
            
            $(this).css(
                'transform',
                style.replace(/none|rotate\([^)]*\)/, '') + 'rotate(' + m[1] + rotateUnits + ')'
            );
        }
    }
    
    // Note that scale is unitless.
    $.fn.scale = function (val, duration, options)
    {
        var style = $(this).css('transform');
        
        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/scale\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }
            
            return 1;
        }
        
        $(this).css(
            'transform',
            style.replace(/none|scale\([^)]*\)/, '') + 'scale(' + val + ')'
        );
    }

    // fx.cur() must be monkey patched because otherwise it would always
    // return 0 for current rotate and scale values
    var curProxied = $.fx.prototype.cur;
    $.fx.prototype.cur = function ()
    {
        if (this.prop == 'rotate')
        {
            return parseFloat($(this.elem).rotate());
        }
        else if (this.prop == 'scale')
        {
            return parseFloat($(this.elem).scale());
        }
        
        return curProxied.apply(this, arguments);
    }
    
    $.fx.step.rotate = function (fx)
    {
        $(fx.elem).rotate(fx.now + rotateUnits);
    }
    
    $.fx.step.scale = function (fx)
    {
        $(fx.elem).scale(fx.now);
    }
    
    /*
    
    Starting on line 3905 of jquery-1.3.2.js we have this code:
    
    // We need to compute starting value
    if ( unit != "px" ) {
        self.style[ name ] = (end || 1) + unit;
        start = ((end || 1) / e.cur(true)) * start;
        self.style[ name ] = start + unit;
    }
    
    This creates a problem where we cannot give units to our custom animation
    because if we do then this code will execute and because self.style[name]
    does not exist where name is our custom animation's name then e.cur(true)
    will likely return zero and create a divide by zero bug which will set
    start to NaN.
    
    The following monkey patch for animate() gets around this by storing the
    units used in the rotation definition and then stripping the units off.
    
    */
    
    var animateProxied = $.fn.animate;
    $.fn.animate = function (prop)
    {
        if (typeof prop['rotate'] != 'undefined')
        {
            var m = prop['rotate'].toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/);
            if (m && m[5])
            {
                rotateUnits = m[5];
            }
            
            prop['rotate'] = m[1];
        }
        
        return animateProxied.apply(this, arguments);
    }
})(jQuery);


//jquery css transform


(function ($) {
    // Monkey patch jQuery 1.3.1+ css() method to support CSS 'transform'
    // property uniformly across Webkit/Safari/Chrome and Firefox 3.5.
    // 2009 Zachary Johnson www.zachstronaut.com
    function getTransformProperty(element)
    {
        // Try transform first for forward compatibility
        var properties = ['transform', 'WebkitTransform', 'MozTransform'];
        var p;
        while (p = properties.shift())
        {
            if (typeof element.style[p] != 'undefined')
            {
                return p;
            }
        }
        
        // Default to transform also
        return 'transform';
    }
    
    var proxied = $.fn.css;
    $.fn.css = function (arg)
    {
        // Find the correct browser specific property and setup the mapping using
        // $.props which is used internally by jQuery.attr() when setting CSS
        // properties via either the css(name, value) or css(properties) method.
        // The problem with doing this once outside of css() method is that you
        // need a DOM node to find the right CSS property, and there is some risk
        // that somebody would call the css() method before body has loaded or any
        // DOM-is-ready events have fired.
        if
        (
            typeof $.props['transform'] == 'undefined'
            &&
            (
                arg == 'transform'
                ||
                (
                    typeof arg == 'object'
                    && typeof arg['transform'] != 'undefined'
                )
            )
        )
        {
            $.props['transform'] = getTransformProperty(this.get(0));
        }
        
        // We force the property mapping here because jQuery.attr() does
        // property mapping with jQuery.props when setting a CSS property,
        // but curCSS() does *not* do property mapping when *getting* a
        // CSS property.  (It probably should since it manually does it
        // for 'float' now anyway... but that'd require more testing.)
        if (arg == 'transform')
        {
            arg = $.props['transform'];
        }
        
        return proxied.apply(this, arguments);
    };
})(jQuery);

