$(function() 
{
	// email page to colleague
    $('.emailCollegaue').bind('click',function()
	{
	alert('');
		$(this).attr("href","mailto:?subject=" + encodeURIComponent("SureSkills Page Recommendation") + "&body=" + encodeURIComponent("SureSkills would like to recommended: " + document.title + ":\n\nhttp://www.sureskills.com" + window.location.pathname + window.location.search));
    });       
	
	
	//
	$('#searchbutton').val("");
	$('.frm_search').focus(function() {
		$(this).val('');
	});

	$('#right_nav p.news_content:odd').css({'backgroundColor':'#e4f4ce'});
	// blog even color
	$('#content .post.xfolkentry:even').css({'backgroundColor':'#ececec'});
	/*$('a.train_dev').bind('click',function()
	{
		$('a.topnav_links:eq(1)').css({'backgroundColor':'blue'});
	});*/
	//================ load header ====================	
	$("header").load("header.html");	
	//================ load footer ====================	
	$("#footer_center").load("footer.html");

	// load sureskills tweets
	$(".tweet").tweet({
		username: ["sureskills"],
		join_text: "auto",
		avatar_size: 32,
		count: 3,
		loading_text: '<p id=loading>' + 'loading tweets...' + '</p>'
	});		
	// ====== rotate upcoming courses =========
	$('.our_courses').hide();                         
    $('#loader').append("<img src='images/loader.gif' class='loadericon' />"); 
    $('.loadericon').show(200),setTimeout(function()
    {
                $('#loader').hide();
                $('.our_courses').fadeIn('slow');   
               
                setInterval(scrollnow, 4000);
       
                function scrollnow() {
                      $('.our_courses li:first-child').slideUp(function(){
                        $(this).appendTo($('.our_courses')).show();
                      });     
                }
           
                },2000);  	
	// ======== trim long course names ===========
        $('.our_courses li a').text(function(index) {
			$(this).text($(this).text().substring(0,45)+"...").css({'fontSize':'0.7em'});                    
        });           	
	//============================================
	
	// ======== trim dropdown course names ===========
        $('#selCourseTitles option').text(function(index) {
			$(this).text($(this).text().substring(0,50)+"...");                
        });           	
	//============================================	
	
	//================= create new course dropdowns ==================		
		
	
		$('ul#training_articles li a.tab_content_links2').text(function(index) {
			var x = $(this).text(); 
			$('#categoryName').append(
                    $('<option></option>').text(x)
                );           
            });  
            //------------------------------------------
            $('ul#training_articles li:eq(0) a:not(a.tab_content_links2)').text(function(index) {
                var x = $(this).text();
                var myhref = $(this).attr('href');
                $('#subdrop1').append(
                   
                    $('<option value="'+myhref+'"></option>').text(x)
                );                       
            });    
			//------
            $("#subdrop1").change(function(e) {
                window.location.href = $(this).val();
            });			
            //------------------------------------------
            $('ul#training_articles li:eq(1) a:not(a.tab_content_links2)').text(function(index) {
                var x = $(this).text();
                var myhref = $(this).attr('href');
                $('#subdrop2').append(
                   
                    $('<option value="'+myhref+'"></option>').text(x)
                );                       
            });    
			//------
            $("#subdrop2").change(function(e) {
                window.location.href = $(this).val();
            });	
            //------------------------------------------
            $('ul#training_articles li:eq(2) a:not(a.tab_content_links2)').text(function(index) {
                var x = $(this).text();
                var myhref = $(this).attr('href');
                $('#subdrop3').append(
                   
                    $('<option value="'+myhref+'"></option>').text(x)
                );                       
            });    
			//------
            $("#subdrop3").change(function(e) {
                window.location.href = $(this).val();
            });		
            //------------------------------------------
            $('ul#training_articles li:eq(3) a:not(a.tab_content_links2)').text(function(index) {
                var x = $(this).text();
                var myhref = $(this).attr('href');
                $('#subdrop4').append(
                   
                    $('<option value="'+myhref+'"></option>').text(x)
                );                       
            });    
			//------
            $("#subdrop4").change(function(e) {
                window.location.href = $(this).val();
            });				
			//----------------------------------------
           $('#categoryName').change(function() {
           
            var courseVal = $(this)[0].selectedIndex;

              if(courseVal == 1)
              {
                $('#subdrop1').show();
				$('#subdrop2').hide();
				$('#subdrop3').hide();
				$('#subdrop4').hide();
              }      
              if(courseVal == 2)
              {
				$('#subdrop1').hide();
                $('#subdrop2').show();
				$('#subdrop3').hide();
				$('#subdrop4').hide();
              } 	
              if(courseVal == 3)
              {
				$('#subdrop1').hide();
                $('#subdrop2').hide();
				$('#subdrop3').show();
				$('#subdrop4').hide();
              } 		
              if(courseVal == 4)
              {
				$('#subdrop1').hide();
                $('#subdrop2').hide();
				$('#subdrop3').hide();
				$('#subdrop4').show();
              } 			  
           });	
	
	// rotate news items                    
            setInterval(scrollnews, 4000);
           
            function scrollnews()
            {
			
            $('#right_nav p.news_content:eq(0)').slideUp('slow',function()
                                                                {
                                                                $(this).show().insertAfter('p.news_content:last-child');
                                                                //$(this).appendTo($('p.news_content:last-child')).after().show();
                                                                });
            }

  		
});
