//options
	var rttheme_slider_time_out = jQuery("meta[name=rttheme_slider_time_out]").attr('content');
	var rttheme_slider_numbers = jQuery("meta[name=rttheme_slider_numbers]").attr('content');
	var rttheme_template_dir = jQuery("meta[name=rttheme_template_dir]").attr('content');

//home page slider

	jQuery(document).ready(function(){
		var slider_area;
		var slider_buttons;

		// Which slider
		if (jQuery('#slider_area').length>0){
			
			// Home Page Slider
			slider_area="#slider_area";	
			if(rttheme_slider_numbers=='true'){slider_buttons="#numbers";}
		
		
			jQuery(slider_area).cycle({ 
				fx:     'fade', 
				timeout:  rttheme_slider_time_out, 
				pager:  slider_buttons, 
				cleartype:  1,
				pagerAnchorBuilder: function(idx) { 
					return '<a href="#" title=""><img src="'+rttheme_template_dir+'/images/pixel.gif" width="14" heigth="14"></a>'; 
				}
			});
		}
 
		// portfolio slider
		if (jQuery('.portfolio_slides').length>0){ 
			
			slider_area=".portfolio_slides";
			
			jQuery(slider_area).cycle({ 
				fx:     'fade',  
				timeout: 4000,
				prev:    '.left',
				next:    '.right'
			});				

		}
		


		
		
	});

// roadmap
jQuery(document).ready(function($)
{
		var $roadmap = $('#roadmap'),
			$filter = $roadmap.find('#filter'),
			$filter_a = $filter.find('a'),
			$timeline = $roadmap.find('#timeline');
			
		//$timeline.find('li span').tooltip({relative: true, position: "bottom right", offset: [-65, -368]});
		
		/*$tooltip.find('.close').click(function(e) { 
			$(this).parent().parent().hide().siblings('span').removeClass('active');
			e.preventDefault();
		});
		
		$tooltip.find('h5').click(function() {
			var $this = $(this),
				$courses = $this.siblings('.course'),
				$toggle = $this.next('.course');

			$courses.not($toggle).slideUp();
			$toggle.slideToggle();
		});
		
		$triggers.click(function() 
		{ 
			$triggers.not($(this)).each(function() { 
				var $this = $(this);
				$this.removeClass('active');
				$this.siblings('.tooltip').hide();
			});
			
			var $this = $(this);
			$this.siblings('.tooltip').toggle();
			$this.toggleClass('active');
		});*/
		
		if ($timeline.length > 0)
		{
			$timeline.appear(function() { 
			
				var $info = $timeline.find("li:not('.timeline-group')"),
					$triggers = $info.find('span');
				
				$info.delay(1000).each(function() 
				{ 
					var $this = $(this),
						$tooltip = $this.find('.tooltip'),
						mLft = parseInt($this.css('margin-left'), 10),
						mRht = parseInt($this.css('margin-right'), 10),
						w = parseInt($this.outerWidth()),
						ow = parseInt($this.outerWidth(true)),
						$courses = $this.find('.course'),
						maxh = 0,
						totalw = 0;
					
					if (mRht > 0 || (mRht == 0 && mLft == 0)) { $this.css({width:w+"px", marginLeft:"-" + w + "px"}); }
					else { $this.css({width:w+"px", marginLeft: ow+"px"}); }
					
					$courses.fadeTo(0, 0.1);
					$courses.each(function(i) { 
						var $this = $(this),
							v = $courses.length - i;
						
						totalw = totalw + parseInt($this.outerWidth(), 10);
	
						$this.addClass('course-' + v);
					});
					
					$tooltip.css({paddingLeft: (parseInt($tooltip.width()) - totalw) + "px"});
					$tooltip.hide().height('auto');
								
					$this.animate({marginLeft: mLft + "px"}, (Math.floor((10-4)*Math.random()) + 5) * 100);
											
					$this.children('span').click(function() 
					{ 
						if ($this.children('span').hasClass('active'))
						{
							$this.children('span').removeClass('active').animate({paddingTop:"6px", paddingBottom:"6px"}, 250).siblings('.tooltip').slideUp(250, function() { $courses.fadeTo(0, 0.1); });
						}
						else
						{					
							$triggers.not($this.children('span')).removeClass('active').animate({paddingTop:"6px", paddingBottom:"6px"}, 250).siblings('.tooltip').slideUp(250, function() { $courses.fadeTo(0, 0.1); });
							
							$this.children('span').addClass('active').animate({paddingTop:"16px", paddingBottom:"16px"}, 250).siblings('.tooltip').slideDown(250, function() { 
								$courses.each(function(i) {
									var $this = $(this),
										h = parseInt($this.height(), 10);
										
									$this.delay(250 * (i + 1)).fadeTo(250, 1);
		
									if (h > maxh) { maxh = h; }
								});
								$courses.height(maxh  + "px");
							});
						}
					});
					
				});
			});			
		}
		
		$filter_a.click(function(e) 
		{ 
			e.preventDefault();

			var $this = $(this),
				$courses = $timeline.find("li:not('.timeline-group')"),
				hsh = $this.attr('href').substring(1),
				to_show = [];
			
			if ($this.attr("href").substring(1) == "showall") 
			{
				if ($this.hasClass('active')) {	return false; }
				else 
				{
					 $this.toggleClass('active');
					 $filter_a.not('#showall').removeClass('active');
				}
			}
			else
			{
				$this.toggleClass('active');
				$filter_a.filter('#showall').removeClass('active');
			}
					
			if ($filter_a.filter('#showall').hasClass('active'))
			{
				$filter_a.not('#showall').removeClass('active');
				$filter_a.each(function(i) { 
					to_show[i] = $(this).attr("href").substring(1);
				});	
			}
			else
			{
				$filter_a.filter('.active').each(function(i) { 
					to_show[i] = $(this).attr("href").substring(1);
				});	
			}
			
			$courses.each(function() { 
				var visible = false,
					$this = $(this);
					
				for (i=0;i<to_show.length;i++)
				{
					if ($this.hasClass(to_show[i])) { visible = true; break; }
				}
				
				if (visible == false) 
				{ 
					$this.fadeTo(0,0.1); 
				} 
				else 
				{ 
					$this.fadeTo(0, 1); 
				}
			});
						
		});
});

//pretty photo
	jQuery(document).ready(function(){
		jQuery("a[rel^='prettyPhoto']").prettyPhoto();
	});


//image effects 
	jQuery(document).ready(function(){
			var image_e= jQuery(".image.portfolio, .image.product_image");
			image_e.mouseover(function(){jQuery(this).stop().animate({ opacity:0.6
					}, 400);
			}).mouseout(function(){
				image_e.stop().animate({ 
					opacity:1
					}, 400 );
			});
	});

//validate contact form
jQuery(document).ready(function(){

		// show a simple loading indicator
		var loader = jQuery('<img src="'+rttheme_template_dir+'/images/loading.gif" alt="loading..." />')
			.appendTo(".loading")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		jQuery.validator.messages.required = "";
		var v = jQuery("#validate_form").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
		
		jQuery("#reset").click(function() {
			v.resetForm();
		});
 });


//cufon fonts
var rttheme_disable_cufon= jQuery("meta[name=rttheme_disable_cufon]").attr('content');
if(rttheme_disable_cufon!='true') {
	jQuery(document).ready(function(){
		Cufon.replace('h1,h2,h3,h4,h5,h6,.portfolio_categories ul,.title a', {hover: true});
	});
}	
	
//RT single level drop down menu
function rt_navigation(){

	var rt_dd_menu = jQuery(".navigation ul.navigation > li");	
	var first_li_items = jQuery(".navigation ul.navigation li > ul");
	
	first_li_items.each(function(){
		 jQuery(this).find('>li:first').addClass('first_li'); // class for first li
		 jQuery(this).find('>li:last a').addClass('last_li'); // remove last border

	});
	
	//current item
	jQuery(".navigation ul.navigation >li .current_page_item").parent("li:eq(0)").addClass('active');
	 
	//first-last list items
	rt_dd_menu.each(function(){

		
		jQuery(this).children("ul:eq(0)").addClass('first_ul');
		 jQuery(".navigation ul.navigation li > ul").addClass('first_ul');
		 jQuery(this).find('li:first').addClass('first_li'); // class for first li
		 jQuery(this).find('li:last a').addClass('last_li'); // remove last border
	});
		
		
	//hover		 
	jQuery(".navigation ul.navigation > li").hover(function() {
		jQuery(this).addClass('li_active');
		jQuery(this).children("a:eq(0)").addClass('a_active');
		jQuery(this).find('ul:first').stop().css({overflow:"hidden", height:"auto", display:"none",'paddingTop':'5px','paddingBottom':'15px'}).slideDown(200, function(){jQuery(this).css({overflow:"visible", height:"auto"});});
	}, function() {
		jQuery(this).find('ul:first').stop().slideUp(200, function(){jQuery(this).css({overflow:"hidden", display:"none"});});
		var active_class=jQuery(this).attr("class");			
		if (active_class!="active"){	
			jQuery(this).removeClass('li_active');
			jQuery(this).children("a:eq(0)").removeClass('a_active');
		}
	});
}

jQuery(document).ready(function() {
	rt_navigation();
});

 

//search field function
jQuery(document).ready(function() {
	var search_text=jQuery(".search_bar .search_text").val();

	jQuery(".search_bar .search_text").focus(function() {
		jQuery(".search_bar .search_text").val('');
	})
});
	
	
	
//product tabs
jQuery(document).ready(function() {
if (jQuery('#tabs').length>0){	
	jQuery('#tabs > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
}
});



//preloading 
jQuery(function () {
	//jQuery('.preload').hide();//hide all the images on the page
	jQuery('.play,.magnifier').css({opacity:0});
	jQuery('.preload').css({opacity:0});
	jQuery('.preload').addClass("animated");
	jQuery('.play,.magnifier').addClass("animated_icon");
});


var i = 0;//initialize
var cint=0;//Internet Explorer Fix
jQuery(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var cint = setInterval("doThis(i)",70);//500 is the fade in speed in milliseconds

});

function doThis() {
	var images = jQuery('.preload').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		clearInterval(cint);//When it reaches the last image the loop ends
	}
	//jQuery('.preload:hidden').eq(i).fadeIn(500);//fades in the hidden images one by one
	jQuery('.animated_icon').eq(0).animate({opacity:1},{"duration": 500});
	jQuery('.animated').eq(0).animate({opacity:1},{"duration": 500});
	jQuery('.animated').eq(0).removeClass("animated");
	jQuery('.animated_icon').eq(0).removeClass("animated_icon");
	i++;//add 1 to the count
}


function checkphonelen(phone)
{
	if(phone.value.length < 10 )
		phone.style.borderColor  = "#FF0000";
	else
		phone.style.borderColor  = "#D0D1D6";
}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}
 
jQuery(document).ready(function($){
  try
  {
	$(".video-launch").fancybox({
		// onComplete: function(){
			
			// if($.browser.msie){
			
				// $f('flow', '/wp-content/themes/ICD/swf/flowplayer-3.2.7.swf', '/wp-content/themes/ICD/videos/icd10.mp4');
				// $f(0).play();
			
			// }
			// else{
			
				// $("video").VideoJS();
			
			// }
		
		// },
		// onClosed: function(){
			
			// if($.browser.msie){
				// $f().pause();
			// }
			// else{
				// $("video")[0].player.pause();
			// }
		
		// }
	});
  }
  catch(err)
  {
  }
			
  try
  {
	if(window.location.hash == '#consultui-video'){
	
		$('.video-launch').click();
	
	}
  }
  catch(err)
  {
  }
  
});
