jQuery.fn.hzShadow = function(settings){
	
	if(($.browser.msie) && ($.browser.version <= 6.0)) { return false; }
	
	var self = this;
	opt = jQuery.extend({
		folder: 'shadow'
	}, settings);
	
	var elemId = this.attr('id');
	var id;
	
	var elemH = this.height();

	if(elemId != 'undefined')
		id = elemId + '_shadow';
	else
		alert('elem needs id');
	
	cnr = [ 't', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl' ];
	
	imgLength = cnr.length;
	
	for(var i = 0; i < imgLength; i++) {
		this.prepend('<div id="' + id + '_' + i + '" class="shadow ' + cnr[i] + '" style="position:absolute;margin:0;padding:0;border:0;outline:0; "></div>');
	}
	
	var img = [];
	for(var i = 0; i < imgLength; i++) { 
		imgSrc = opt.folder + '/' + cnr[i] + '.png';
		img[i] = new Image();
		img[i].src = imgSrc;
		img[i].index = i;
		img[i].onload = function(){
			addShadow(this, id);
		}
	}
	
//	$('#' + elemId).pngFix();
	
	function addShadow(img, id){
		var i = img.index;
		switch(i) {
			case 0:
			   $('#'+ id + '_' + i).css(
					{ 
						'left': 0 + 'px',
						'top': '-' + img.height + 'px',
						'width': '100%',
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') repeat-x'
					 });
			 
			   break;
			  case 1:
			   $('#'+ id + '_' + i).css(
					{ 
						'right': '-' + img.width + 'px',
						'top': '-' + img.height + 'px',
						'width': img.width,
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') no-repeat'
					 });
			 
			   break;
			  case 2:
			   $('#'+ id + '_' + i).css(
					{ 
						'right': '-' + img.width + 'px',
						'top': 0 + 'px',
						'width': img.width + 'px',
						'height': elemH + 'px',
						'background': 'transparent url(' + img.src + ') repeat-y'
					 });
			 
			   break;
			  case 3:
			   $('#'+ id + '_' + i).css(
					{ 
						'right': '-' + img.width + 'px',
						'top': '100%',
						'width': img.width + 'px',
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') no-repeat'
					 });
			 
			   break;
			case 4:
			   $('#'+ id + '_' + i).css(
					{ 
						'left': 0 + 'px',
						'top': '100%',
						'width': '100%',
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') repeat-x'
					 });
			 
			   break;
			  case 5:
			   $('#'+ id + '_' + i).css(
					{ 
						'left': '-' + img.width + 'px',
						'bottom': '-' + img.height + 'px',
						'width': img.width + 'px',
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') no-repeat'
					 });
			 
			   break;
			  case 6:
			   $('#'+ id + '_' + i).css(
					{ 
						'left': '-' + img.width + 'px',
						'top': 0 + 'px',
						'width': img.width + 'px',
						'height': elemH + 'px',
						'background': 'transparent url(' + img.src + ') repeat-y'
					 });
			 
			   break;
			  case 7:
			   $('#'+ id + '_' + i).css(
					{ 
						'left': '-' + img.width + 'px',
						'top': '-' + img.height + 'px',
						'width': img.width + 'px',
						'height': img.height + 'px',
						'background': 'transparent url(' + img.src + ') no-repeat'
					 });
			 
			   break;
		}
	}
}


$(document).ready(function() {
	
	// shadow
	$('#wrap-toolbar').hzShadow( { folder: '/assets/img/shadow/' } );
	
	var brH = $("#body-main").height();
	var blH = $("#body-secondary").height();
	var shadowH = (brH >= blH) ? brH : blH;
	$("#shadow-body-main").height(shadowH)
	$('#shadow-body-main').hzShadow( { folder: '/assets/img/shadow/' } );
	
	$("#shadow-body-secondary").height(shadowH);
	$('#shadow-body-secondary').hzShadow( { folder: '/assets/img/shadow/' } );

	$('#shadow-body-full').height(shadowH);
	$('#shadow-body-full').hzShadow( { folder: '/assets/img/shadow/' } );   
	
	
	// form button over effect	
	$('#form-updates .submit').hover(function(){
		$(this).css( { backgroundPosition: '0 -19px'} );
	},function(){
		$(this).css( { backgroundPosition: '0 0'} );		
	});
	
	$('#form-contact .submit').hover(function(){
		$(this).css( { backgroundPosition: '0 -26px'} );
	},function(){
		$(this).css( { backgroundPosition: '0 0'} );		
	});
		
	
	// button hover effect.
	var findElement = '';
	$('.btn').hover(function(){
		if(!($(this).find('span').length > 0)) { findElement = 'img'; } else { findElement = 'span'; }
		
		if(!$('.active', this).length > 0){
			$(this).find(findElement).css( { 'marginTop': - ( $(this).find(findElement).height() / 2) + 'px' } );				
		}
	}, function(){
     	if(!$('.active', this).length > 0){ 
			$(this).find(findElement).css( { 'marginTop': 0 + 'px' } );
         }
	});  
	
	// Hide field label
	$('#form-updates label').show();
	$('#form-updates .field').val('').focus(function(){
		$(this).siblings('label').hide();
	}).blur(function(){
		if($(this).val() == '')
			$(this).siblings('label').show();
	});
	
	// //photo gallery
	// if(jQuery.broswser = 'msie' && jQuery.browser.version >= '6.0'){
	//    	$('#wrap-gallery ul li div').hover(function(e){
	// 		$(this).hoverFlow(e.type, { 'width': '100%', 'height': '100%', 'top': 0 }, 200);
	// 	}, function(e){              
	// 		$(this).hoverFlow(e.type, { 'width': '80%', 'height': '80%', 'top': 9 + 'px' }, 100);
	// 	}); 
	// }
      
	if($(".popup-video").size() > 0){
		$(".popup-video").fancybox({
			'titleShow'	: false,
			'overlayShow' : false,
			'autoScale' : false,
			'padding' : 0,
			'margin': 0,
			'height': 387,
			'width': 935,
			'speedIn' : 300, 
			'transitionIn' : 'fade',
			'transitionOut'	: 'none',
			'type': 'iframe'
		});		
	}  	




});
