Cufon.replace('#navigation a', { fontFamily: 'GothamBold', textShadow: '1px 1px 1px #3a3a3a'});
Cufon.replace('#header h2 , #content .main .info-price .price-2 h2 , #content .main .info-price .price-1 h2, #content .main .info-price .price-2 h2 ', { fontFamily: 'GothamBold' }); 
Cufon.replace('#content .part-1 .sidebar-home .info h3,#content .col .info.full .details h3, #content .detail .reason h3, #content .detail h2, #content .main .info h2 , .story-headline, #content .form h2, #content .main .box-content h2, #content .list-feature h2,#content .part-1 h2.slogan, #content .part-1 .image .description h3, #content .main .info-price .price-1 h2', { fontFamily: 'GothamLight' });


(function($) {
	// our global variables
	var _current 	= 0; // current active child-object in the big list
	var _timeout 	= null; // timeout variable for the auto slider
	
	$.fn.liivSlider = function(options) {
		var _object		= $(this);
		var _content 	= $(this).find('.videos'); // main slider content selection
		var _li			= $(this).find('li');
		var _each_length = 160;
		// alert(_length);
		if(!_li.length){
			return;
		} 
		var _length		= _li.length * _each_length;
		$(_content).width(_length);
		// alert(_each_length);
		
		// run the auto
		$(_content).children('li:eq(' + _current + ')').fadeIn();
		// autoRotation();
		
		// handle previous/next navigation
		$(_object).find('.buttons').children('.prev').children('a').click(function(){
			stopTheAuto();
			
			if(_current == 0) {
				_current = $(_content).children('li').length - 3;
			} else {
				_current -= 1;
			}
			
			mainAction(_current);
			
			return false;
		});

		$(_object).find('.buttons').children('.next').children('a').click(function(){
			stopTheAuto();

			if(_current >= $(_content).children('li').length - 3) {
				_current = 0; 
			} else {
				_current += 1;
			}
			
			mainAction(_current);
			
			return false;
		});
		
		function stopTheAuto() {
			clearTimeout(_timeout);
		}
		
		function autoRotation() {
			var _nid = _current;
			
			if(_current >= $(_content).children('li').length - 3) {
				_nid = 0; // reset the loop
			} else {
				_nid = _current + 1;
			}
			
			_timeout = setTimeout(function() {
				process(_nid);
			}, 4000);
		}
		
		function process(_nid) {
			_current = _nid;
			mainAction(_current, true);
		}
	
		function mainAction(_current, _flag) {
			// alert(_class_name);
			// $(_content).children('li').fadeOut(100);
			if(_flag) {
				$(_content).animate({'margin-left': -(_current * _each_length)}, 800,  function(){ autoRotation(); }); //.children('li:eq(' + _current + ')').fadeIn(800, function(){ autoRotation(); });
			} else {
				$(_content).animate({'margin-left': -(_current * _each_length)}, 800);
			}
		}
		

	}
})(jQuery);



$().ready(function(){
	$('.sidebar-home ul li a').click(function(){
		if(!$(this).parent('li').hasClass('active')) {
			var _index = $(this).parent('li').index();
			$('.images dd').hide();
			$('.images dd:eq(' + _index + ')').fadeIn('fast');
			$('.sidebar-home li').removeClass('active');
			$(this).parent('li').addClass('active');
			$('.sidebar-home a').css({'color':'#624e47'});
			$(this).css({'color':'#fff'});
			// Cufon.now();
		}
		return false;
	});
	
	
	$('.guide a').click(function(){
		$(this).parent('li').parent('ul').parent('.guide').siblings('dl').find('.tooltip').hide();
		var _class = $(this).parent('li').attr('class');
		// alert(_class);
		$(this).parent('li').parent('ul').parent('.guide').siblings('dl').find('.' + _class).children('.tooltip').fadeIn('normal', function(){
			$.scrollTo( $('dl .'+ _class +' .tooltip') , 800 ); 
		});
		
		return false;
	});
	
	$('dl a.number').click(function(){
		$('dd .tooltip').hide();
		var _obj = $(this).siblings('.tooltip');
		_obj.fadeIn('normal', function(){
			$.scrollTo( _obj , 800 );
		});
		return false;
	});
	
	$('#content .main ul.name a').click(function(){
		var _target = $(this).attr('href').substr(1);
		$.scrollTo( $('.' + _target), 800 );
		return false;
	});
	
	$('dl .tooltip a.next').click(function(){
		if(!$(this).parent('div').parent('div').parent('div').parent('dd').next('dd').find('.tooltip').length) {
			var _obj = $('#content .main .box-content .homepage dl dd.one .tooltip');
		} else {
			var _obj = $(this).parent('div').parent('div').parent('div').parent('dd').next('dd').find('.tooltip');
		}
		_obj.fadeIn('normal', function(){
			$.scrollTo( _obj , 800 );
		});
		$(this).parent('div').parent('div').parent('div').hide();
		return false; 
	});
	
	$('#content .part-2 dl dd').click(function(){
		var _link = $(this).find('.read-more').attr('href');
		window.location=_link;
		
		return false;
	});
	
	$('.team-name a').click(function(){
		var _target = $(this).attr('href').substr(1);
		$.scrollTo( '#'+_target, 800, function(){
			$('#'+_target).find('h3.name').animate({ backgroundColor: "#a7bf51"}, 800);  
			
			// .animate({'background': '#000'}, 400) 
			// .animate({'background': '#fff'}, 200)
			// .animate({'background': '#fbecb7'}, 200)
			// .animate({'background': '#fff'}, 100);
		});
		return false;
	});
	
	// casourel
	$('#casourel li a').click(function(){
		var _video = $(this).attr('rel');
		if(isiPhone()){
			var _video_replace = '<a href="http://httpdl.liivmd.com/'+_video+'"'
	   						+ 'style="display:block;width:451px;height:254px;" '
	   						+ 'id="ipad">'
	   						+ '</a>';
			$('.video-player').html(_video_replace);
			$f("ipad", "http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf").ipad();
		} else {
			var _video_replace = '<a id="aplayer" href="http://httpdl.liivmd.com/'+_video+'" style="display: block; width: 451px; height: 254px"></a><script language="JavaScript">$().ready(function(){$f(\'aplayer\',{ src:\'../videos/flowplayer/flowplayer.commercial-3.2.7.swf\',wmode: \'opaque\' }, {key: \'$9f98241970adc957c24\', plugins: {influxis: {url: \'../videos/flowplayer/flowplayer.rtmp-3.2.3.swf\',netConnectionUrl: \'rtmp://planethopefs.fplive.net/planethope\' },	controls: {	url: \'../videos/flowplayer/flowplayer.controls-3.2.5.swf\',backgroundColor: "transparent",backgroundGradient: "none"}},playlist: [{url: \'http://www.liivmdcorp.com/images/video-thumb.jpg\',scaling: \'orig\'},{url: \'mp4:/'+_video+'\',provider: \'influxis\',autoPlay: true, loop: true}]});});</script>';
			$('.video-player').html(_video_replace);
		}
		
	
		return false;
	});
	
	$('#casourel').liivSlider();
	
	// AJAX form validating & submiting
	$('#contact-submit').click(function(){
	  $('#note').hide();

	  var name = $("input#name").val();
	  var email = $("input#email").val();
	  var phone = $("input#phone").val();
	  var message = $("#message").val();

	  var dataString = 'name='+ name + '&email=' + email + '&message=' + message +'&phone='+phone;
	  //alert (dataString);return false;
	  $.ajax({
	    type: "POST",
	    url: "handler.php",
	    data: dataString,
	    success: function(data) {
		  // alert(data);
		  if(data == 1) {
		    $('#note').html('<div class="success"><p>Thank you! Your message has been received.</p><p>We will get back to you as soon as possible.</p></div>').fadeIn();
		  } else {
			$('#note').html('<div class="error">' + data + '</div>').fadeIn();
		  }
	    }
	  });
	  return false;

  });

	// AJAX form validating & submiting
	$('#partnership-submit').click(function(){
	  $('#note').hide();

	  var name = $("input#name").val();
	  var company = $("input#company").val();
	  var phone = $("input#phone").val();
	  var email = $("#email").val();

	  var dataString = 'name='+ name + '&company=' + company + '&phone=' + phone +'&email='+email;
	  //alert (dataString);return false;
	  $.ajax({
	    type: "POST",
	    url: "handler.php",
	    data: dataString,
	    success: function(data) {
		  // alert(data);
		  if(data == 1) {
		    $('#note').html('<div class="success"><p>Thank you! Your message has been received.</p><p>We will get back to you as soon as possible.</p></div>').fadeIn();
		  } else {
			$('#note').html('<div class="error">' + data + '</div>').fadeIn();
		  }
	    }
	  });
	  return false;

  });

	$('#request-submit').click(function(){
	 	 $('#note').hide();

		  var name = $("input#name").val();
		  var company = $("input#company").val();
		  var message = $("input#message").val();
		  var email = $("#email").val();

		  var dataString = 'name='+ name + '&company=' + company + '&message=' + message +'&email='+email;
		  //alert (dataString);return false;
		  $.ajax({
		    type: "POST",
		    url: "handler.php",
		    data: dataString,
		    success: function(data) {
			  // alert(data);
			  if(data == 1) {
			    $('#note').html('<div class="success"><p>Thank you! Your message has been received.</p><p>We will get back to you as soon as possible.</p></div>').fadeIn();
			  } else {
				$('#note').html('<div class="error">' + data + '</div>').fadeIn();
			  }
		    }
		  });
		  return false;

	});
	
	
	$('#request-demo').submit(function(){
		var name = $("input#name").val();
		  var company = $("input#company").val();
		  var message = $("#message").val();
		  var email = $("#email").val();

		  var dataString = 'name='+ name + '&company=' + company + '&message=' + message +'&email='+email;
		  //alert (dataString);return false;
		  $.ajax({
		    type: "POST",
		    url: "/handler.php",
		    data: dataString,
		    success: function(data) {
			  	if(data == 1) {
				    $('#note').html('<div class="success">Thank you! Your message has been received. We will get back to you as soon as possible.</div>').fadeIn();
					setTimeout("$.LightBoxObject.close()", 2000);
				  } else {
					$('#note').html('<div class="error">' + data + '</div>').fadeIn();
				  }
				
		    }
		  });
		// $.LightBoxObject.resize(660, 480);
		return false;
	});
	
	
	var _video_id = 0;
	$('.exceed').click(function(){
		_video_id = $(this).attr('rel').substr(1);
		$('#exceed-trigger').trigger('click');
		return false;
	});
	
	$('.videolink').click(function(){
		_video_id = $(this).attr('rel').substr(1);
	})
	
	
	// hashing - temporary no use
//	var hash = window.location.hash;
//	if(hash) {
//		var _id = hash.substr(2);
//		var dataString = 'action=view&id='+ _id;
//		
//		$.ajax({
//		    type: "POST",
//		    url: "/video/ajax",
//		    data: dataString,
//		    success: function(_data) {
//			  	if(_data) {
//			  		if(_data == 'exceed') {
//			  			$('#exceed-trigger').trigger('click');
//			  		} else {
//			  			if(isiPhone()){
//					   		jQuery('.video-player').html('<a href="http://httpdl.liivmd.com"'
//			   						+ 'style="display:block;width:640px;height:360px;" '
//			   						+ 'id="ipad">'
//			   						+ '</a>'
//			   						);
//					   		$f("ipad", "http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf").ipad();
//					   		
//					   		$('#video-trigger').trigger('click');
//			   				
//				  		} else {
//				  			jQuery('.video-player').html(
//				  					'<a href="#" id="aplayer"><object id="aplayer_api" width="100%" height="100%" type="application/x-shockwave-flash" data="/videos/flowplayer/flowplayer.commercial-3.2.7.swf">'
//				  					+'<param value="true" name="allowfullscreen">'
//				  					+'<param value="always" name="allowscriptaccess">'
//				  					+'<param value="high" name="quality">'
//				  					+'<param value="false" name="cachebusting">'
//				  					+'<param value="#000000" name="bgcolor">'
//				  					+'<param value="opaque" name="wmode">'
//				  					+'<param name="flashvars" value="config={\'key\':\'$9f98241970adc957c24\',\'plugins\':{\'influxis\':{\'url\':\'/videos/flowplayer/flowplayer.rtmp-3.2.3.swf\',\'netConnectionUrl\':\'rtmp://planethopefs.fplive.net/planethope\'},\'controls\':{\'url\':\'/videos/flowplayer/flowplayer.controls-3.2.5.swf\',\'backgroundColor\':\'transparent\',\'backgroundGradient\':\'none\'}},\'playlist\':[{\'url\':\'http://www.liivmdcorp.com/images/video-thumb.jpg\',\'scaling\':\'orig\'},{\'url\':\'mp4:'+_data+'\',\'provider\':\'influxis\',\'autoPlay\':true}],\'playerId\':\'aplayer\',\'clip\':{\'url\':\'http://httpdl.liivmd.com'+_data+'\'}}">'
//				  					+'</object></a>');
//				  			$('#video-trigger').trigger('click');
//				  			
//				  		}
//			  		}
//			  		
//			  		
//			  		
//			  		
//				} else {
//					alert('Error occur! Please contact our sales for help. We\'re really sorry about this');
//				}
//				
//		    }
//		});
//	}
	
	
	$('#code-form').live('submit', function(){
		var _code = $(this).find('#code').val();
		var dataString = 'code='+ _code;
		
		$.ajax({
		    type: "POST",
		    url: "/video/ajax",
		    data: dataString,
		    success: function(data) {
			  	if(data == 1) {
			  		var _link= '/video/page';
			  		$('#thankyou-trigger').trigger('click');
			  		setTimeout('$.LightBoxObject.close(); window.location = _link;', 2000);
			  		
					return false;
				  } else {
					$('#exceed #note').html('<div class="error">' + data + '</div>').fadeIn();
				  }
				
		    }
		  });
		
		return false;
	});
	
	
	function isiPhone(){
	    return (
			(navigator.platform.indexOf("iPad") != -1) ||
	        (navigator.platform.indexOf("iPhone") != -1) ||
	        (navigator.platform.indexOf("iPod") != -1)
	    );
	}
	
	
	// video modal playing
//	$('.view-video').click(function(){
//		
//		var _id = $(this).attr('rel').substr(1);
//		var dataString = 'action=view&id='+ _id;
//	
//		
//		$.ajax({
//		    type: "POST",
//		    url: "/video/ajax",
//		    data: dataString,
//		    success: function(_data) {
//			  	if(_data) {
//			  		if(_data == 'exceed') {
//			  			$('#exceed-trigger').trigger('click');
//			  		} else {
//			  			if(isiPhone()){
//					   		jQuery('.video-player').html('<a href="http://httpdl.liivmd.com"'
//			   						+ 'style="display:block;width:640px;height:360px;" '
//			   						+ 'id="ipad">'
//			   						+ '</a>'
//			   						);
//					   		$f("ipad", "http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf").ipad();
//					   		$('#video-trigger').trigger('click');
//			   				
//				  		} else {
//				  			jQuery('.video-player').html(
//				  					'<a href="#" id="aplayer"><object id="aplayer_api" width="100%" height="100%" type="application/x-shockwave-flash" data="http://www.liivmdcorp.com/videos/flowplayer/flowplayer.commercial-3.2.7.swf">'
//				  					+'<param value="true" name="allowfullscreen">'
//				  					+'<param value="always" name="allowscriptaccess">'
//				  					+'<param value="high" name="quality">'
//				  					+'<param value="false" name="cachebusting">'
//				  					+'<param value="#000000" name="bgcolor">'
//				  					+'<param value="opaque" name="wmode">'
//				  					+'<param name="flashvars" value="config={\'key\':\'$9f98241970adc957c24\',\'plugins\':{\'influxis\':{\'url\':\'http://www.liivmdcorp.com/videos/flowplayer/flowplayer.rtmp-3.2.3.swf\',\'netConnectionUrl\':\'rtmp://planethopefs.fplive.net/planethope\'},\'controls\':{\'url\':\'http://www.liivmdcorp.com/videos/flowplayer/flowplayer.controls-3.2.5.swf\',\'backgroundColor\':\'transparent\',\'backgroundGradient\':\'none\'}},\'playlist\':[{\'url\':\'http://www.liivmdcorp.com/images/video-thumb.jpg\',\'scaling\':\'orig\'},{\'url\':\'mp4:'+_data+'\',\'provider\':\'influxis\',\'autoPlay\':true}],\'playerId\':\'aplayer\',\'clip\':{\'url\':\'http://httpdl.liivmd.com'+_data+'\'}}">'
//				  					+'</object></a>');
//				  		
//				  			$('#video-trigger').trigger('click');
//				  			
//				  		}
//			  		}
//			  		
//			  		
//			  		
//			  		
//				} else {
//					alert('Error occur! Please contact our sales for help. We\'re really sorry about this');
//				}
//				
//		    }
//		});
//		return false;
//	});
	
});
