$(document).ready(function(){
		$('form').jqTransform({});
});


$(document).ready(function(){
if ($('.section-slider').length){
	var circle_slider = $('.mainslider').bxSlider({
			autoHover: true,
			mode: 'fade',
			pagerActiveClass: 'current',
			controls: false,
			auto: true,
			pause: 5000,
			pager: true
		});
	var small_slider = $('.smallslider').bxSlider({
			autoHover: true,
			mode: 'fade',
			pagerActiveClass: 'current',
			controls: false,
			auto: true,
			pause: 5000,
			pager: true
		});
}
if ($('.innerslider').length){
	var innerslider= $('.innerslider').bxSlider({
			autoHover: true,
			mode: 'fade',
			pagerActiveClass: 'current',
			controls: false,
			auto: true,
			pause: 5000
		});
}


$(".social-ico a,.see-portfolio").hover(function() {
		    $(this).stop().animate({ top:"-4px" }, 200);
		},function(){
		    $(this).stop().animate({ top: "0px"}, 300);
		});



//contentPanel slide up
if ($('.portfolio-items').length){
			$('.overlay').css('opacity',0);
			$('.p-item').css('opacity',0.8);
			$('.p-item').hover(
			function(){
				$(this).find('.overlay').stop(true,true).animate({ opacity: 0.8});
				$(this).stop(true,true).animate({ opacity: 1});
			},
			function(){
				$(this).find('.overlay').stop(true,true).animate({ opacity: 0});
				$(this).stop(true,true).animate({ opacity: 0.8});
			}
		)
	}


if ($('.tooltip').length){

	$('.tooltip').hide();
	var w=0;
	var h=0;
	$('.itemsbox a').hover(
				function(e){
					w=$(this).parent().find('img').width()-18;
					h=$(this).parent().find('img').height()-18;
					$(this).stop(true,false).animate({borderWidth: "9px",width:w+"px",height:h+"px"}, 200 );
					$(this).parent().find('.tooltip').stop(true,true).show();

				},
				function(e){
					w=w+18;
					h=h+18;
					$(this).stop(true,false).animate({borderWidth: "0px",width:w+"px",height:h+"px"}, 200 );
					$(this).parent().find('.tooltip').stop(true,true).hide();
	})
	
	$('.tooltip').mouseenter(function(){
		$(this).fadeOut();
	})
	$('.itemsbox .hastool ').mousemove(function(e){
		var position = $('.itemsbox').offset();
		var _left =((e.pageX-position.left)-this.offsetLeft)-80;
		var _top =((e.pageY-position.top)-this.offsetTop)-230;
		$(this).parent().find('.tooltip').css({'left':_left+'px','top':_top+'px'});

	})
}

});

$(document).ready(function() { 
						   
	if ($('blockquote').length){
		$('blockquote').each(function(){
			var h=$(this).height();
			if (h<95)
				$(this).css('height','95px');
			
				
		})
		
	}
						   
	if ($('#map_canvas').length){
    $('#map_canvas').googleMaps({
        markers: {
            latitude: 	34.095535,
            longitude: -118.344292,
            info: {
                layer: '#gmap-address',
                popup: true
            },
              icon: {
            	image: 'css/images/contact-arrow.gif', 
            	iconSize: '14, 20'
            }
        }
    }); 
	}

if ($('.tooltip-p').length){
		function viewport() {
			return {
				x: $(window).scrollLeft(),
				y: $(window).scrollTop(),
				cx: $(window).width(),
				cy: $(window).height()
			};
		}
		
		
		
		
		//$('.tooltip-p').css('opacity','0');
		var w=0;
		var h=0;
		$('.pitem').hover(function(){
					var v = viewport();
					var tooltip_h=$(this).find('.tooltip-p').height();
					var li_top=$(this).closest('li').position().top;
					var li_height=$(this).closest('li').height();
					var topoffset = $(this).closest('li').offset().top;

					if((topoffset<=(tooltip_h+v.y+50))){
						$(this).find('.tooltip-p').addClass('toparrow');
						//alert('top');
					}
					else{//alert('bottom');
						$(this).find('.tooltip-p').addClass('bottomarrow');
					}
					
					w=$(this).find('img').width()-18;
					h=$(this).find('img').height()-18;
					$(this).find('.hovered').stop(true,false).animate({borderWidth: "9px",width:w+"px",height:h+"px"}, 200 );
					$(this).find('.toparrow').stop(true,true).css('display','block').animate({'margin-top':'-10px'}, "fast");
					$(this).find('.bottomarrow').stop(true,true).css('display','block').animate({'margin-bottom':'-10px'}, "fast");
				},
		function(){
					w=w+18;
					h=h+18;
					$(this).find('.hovered').stop(true,false).animate({borderWidth: "0px",width:w+"px",height:h+"px"}, 200 );
					$(this).find('.toparrow').stop(true,true).animate({'margin-top':'0'}, "fast").css({'display':'none'}).removeClass('toparrow');																																	
					$(this).find('.bottomarrow').stop(true,true).animate({'margin-bottom':'0'}, "fast").css({'display':'none'}).removeClass('bottomarrow');
					
				})
	}//end if popup





	function clear_form_elements(ele) {
	
		$(ele).find(':input').each(function() {
			switch(this.type) {
				case 'password':
				case 'select-multiple':
				case 'select-one':
				case 'text':
				case 'textarea':
					$(this).val('');
					break;
				case 'checkbox':
					this.checked = false;
			}
		});
	
	}
	function loading(){
		$("#result").hide().slideDown(1000);		
		$("#result").html('<!--<img src="css/images/ajax-loader.gif"/>-->Processing...');		
		$(".frm").find("span.msg").html('').hide();
	};

$('[type=text],[type=radio],[type=checkbox], textarea').focus(function () {
	$(this).prevUntil().find("span").slideUp(1000).html('');
 });



//rpeair and special orders form 
$(".frm").submit(function() {
	loading();
	var formData = $(this).serialize();
	$.ajax({
		url:'php/send_mail.php',
		type:'post',
		data:formData,
		success: function(msg){
			$("#result").html('');
			
			var result =eval(jQuery.parseJSON( msg));
			$('#validateUsername').html(result['name']);
			$('#validatePhone').html(result['phone']);
			$('#validateEmail').html(result['email']);
			$('#validateSite').html(result['site']);
			$('#validateBesttime').html(result['besttime']);
			$(".frm").find("span.msg").slideDown(1000);
			
			if (result['error']==0){
				clear_form_elements('.frm');
				$("#result").addClass('ok').slideDown(1000).html('Message sent!');
				}
			}
		});
		return false;
	});


}); 


$(function() {
		$( "#tabs" ).tabs();
	});

