function form_input_classes(){
    jQuery('input[type="text"]').addClass('text');
    jQuery('input[type="password"]').addClass('text');
    jQuery('input[type="checkbox"]').addClass('checkbox');
    jQuery('input[type="radio"]').addClass('radiobutton');
    jQuery('input[type="submit"]').addClass('submit');
    jQuery('input[type="image"]').addClass('buttonImage');
}

function form_labelize(){
    jQuery(".labelize input:text").clearingInput();
}   

function cycle_activate(){
    jQuery('#cycle').cycle({
        fx: 'fade',
        timeout: 8000, 
        pager:  '#pager',
before:         change_caption,   pagerClick: change_caption_click
    });
}

function change_caption_click(zeroBasedSlideIndex, slideElement)
{

jQuery('#caption').empty();

    var caption;
    
    if(slideElement.tagName == "A")
    {
     caption = jQuery(slideElement).find('img').attr('rel');
    }else
    {
      caption = jQuery(slideElement).attr('rel');
    }

jQuery('#caption').text(caption);


}

function change_caption(currSlideElement, nextSlideElement, options, forwardFlag)
{
   //console.log(jQuery(nextSlideElement).find('img').attr('rel'));
   //console.log(currSlideElement.tagName);

jQuery('#caption').empty();    

    var caption;
    
    if(nextSlideElement.tagName == "A")
    {
     caption = jQuery(nextSlideElement).find('img').attr('rel');
    }else
    {
      caption = jQuery(nextSlideElement).attr('rel');
    }

jQuery('#caption').text(caption);

}

jQuery(document).ready(function() {

  jQuery('#carousel').jcarousel({
        scroll: 1
    });
 
  form_input_classes();
  form_labelize();
  cycle_activate();
  //image_captions_from_title_attribute();
  init_captions();
  video_gallery();

    //Supressing CSS Fallback for Javascript users
    jQuery("ul#primary-nav li").addClass("hasjs");
                               
    //Hover function for menu rollover
    jQuery("ul#primary-nav li").hover(
      function () {
        jQuery(this).children("ul").fadeIn("fast");
      },

      function () {
        jQuery(this).children("ul").fadeOut("fast"); 
      }
      
    );
    
    var path = location.pathname.substring(1);
    jQuery('#secondary-nav a[href$="' + path + '"]').addClass('selected'); // check path as typed exactly
    jQuery('#secondary-nav a[href$="' + path + '/"]').addClass('selected'); // check path with an extra trailing slash added


});


function init_captions()
{

jQuery('#left img').addcaption();

if(jQuery('#news').length != 0) 
{
  //console.log('test');
  
//console.log('test2');
}

}


function image_captions_from_title_attribute()
{

   var img_array = {};
     console.log('wea are');
   if(jQuery('#news').length != 0) 
   {  
      jQuery('img').each(function(i){
	    console.log('wea are 2');
	    console.log(jQuery(this).attr('title'));
		if(check_title_attribute())
		{
			console.log(jQuery(this).attr('title'));
			
		}else
		{
			img_array.push(this);
		}
	
	  });
	  
	//console.log(img_array);
	
   }

}

function check_title_attribute()
{
	if(jQuery(this).attr('title') != "")
	{
		
		return true;
		
	}else
	{
		console.log('return false');
		return false;
	}
	
	if(jQuery(this).attr('title') != NULL)
	{
		return true;
		
	}else
	{
		console.log('return false');
		return false;
	}
	
}

function video_gallery()
{

jQuery('.video-gallery a').click(function(){

  jQuery('#video-feature-inner').empty();
  jQuery('#video-feature-inner').html('<div id="video-feature-container"></div>');
  video_id = jQuery(this).attr('rel');  

var flashvars = {
  hl: "en",
  fs: "1"
};
var params = {
  menu: "false"
};
var attributes = {
  id: "video-main-feature",
  name: "video-main-feature"
};

swfobject.embedSWF("http://www.youtube.com/v/" + video_id, "video-feature-container", "308", "220", "8","expressInstall.swf", flashvars, params, attributes);

return false;
  

});

}


Cufon.replace('#sidebar-right h3');
Cufon.replace('#sidebar h3');
Cufon.replace('#fellows #news h3');
Cufon.replace('#left.general h1');
Cufon.replace('#bsd h1');
Cufon.replace('#left.general h2, .videos h2');
Cufon.replace('#left.general h3');
Cufon.replace('.general-full-width h1');
Cufon.replace("#sidebar-right blockquote");
Cufon.replace(".cufon");
