$(function(){
    // preload images
    $('<img>').attr('src', '/images/circle_h.png'); //circle hover

   // magic onload scroll
   if($('#work-page').size() && !$('#work-page.index').size())  {
        var scrollSpeed = 900;        
        if ($('#work-page.books').size() || $('#work-page.publication').size() || $('#work-page.author').size()) {
            var innerStep = document.referrer.indexOf(document.domain) >= 0;
            var publicationStep = document.referrer.indexOf('books') > 0 ||
                document.referrer.indexOf('publication') > 0 ||
                document.referrer.indexOf('author') > 0;
            if (innerStep && publicationStep) {
                scrollSpeed = 0;
            }
        }

        if ($('#work-page.response').size()) {
            var innerStep = document.referrer.indexOf(document.domain) >= 0;
            var publicationStep = document.referrer.indexOf('response') > 0;
            if (innerStep && publicationStep) {
                scrollSpeed = 0;
            }
        }


        $.scrollTo('#work-page', scrollSpeed);
    }

   // manage achievements in main page
   if ($('#achievements').size()) {
        var achievements = $('#achievements li');
       $('#achievements li').hover(function(){
           if ($(this).next().size()) {
               $(this).next().addClass('noline');
           }
           
           $(this).addClass('current');

       }, function() {          
           if ($(this).next().size()) {
                $(this).next().removeClass('noline');
           }
           $(this).removeClass('current');
       });
   }
	


   //spy in main page
   if ($('#said').size()) {
        var fadeSpeed = $.browser.msie ? 0 : 400;

        $('#said .current').fadeIn();
		$('#said .arrow').click(function() {
			$('#said .current').fadeOut(fadeSpeed, function(){
				var next  = $(this).removeClass('current').next();			
				next.size() ? next.addClass('current') : $('#said li:first').addClass('current');
				$('#said .current').fadeIn(fadeSpeed);
			});			
		});
   }

   // make rounded wrapper for mail form
   if ($('.mail-n-phone').size()) {      
	  $('.mail-n-phone').corner("14px");
	  $('#order-form-wrapper').corner("10px");
	  $('#order-form').corner("5px");
   }


   // certificates carousel on resume page

   if ($('#certificates').size()) {
       $('<img>').attr('src', '/images/l_link_h.gif');
       $('<img>').attr('src', '/images/r_link_h.gif');
       $('#certificates ul').bxCarousel({
          display_num: 5,
          move:2,
          speed: 700,
          margin:30,
          prev_text: '',
          next_text: ''
       }).bind('moved', function() {
           $('.pp_pic_holder, .pp_overlay, .ppt').remove();
           $("#certificates a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
       });

   }

   if ($('#work-page.response').size()){
        $('<img>').attr('src', '/images/str_ra.gif');
        $('<img>').attr('src', '/images/str_la.gif');
   }


   // mark first h2 header in resume page
   if ($('#resume-blocks').size()) {
       $('#resume-blocks h2:first').addClass('first');
   }

   // mark first h2 header in resume page
   if ($('#responses').size()) {
       $('#responses h2:first').addClass('first');
   }
});


