$(document).ready(function() {
	//external links
	$("a[rel=external]").click(function() { window.open($(this).attr('href')); return false; });

	//fancy.klade.lv
	//single image
	$(".fancybox").fancybox({
    	openEffect : 'none',
    	closeEffect	: 'none',
    	helpers : {
    		title : {
    			type : 'outside'
    		}
    	}
    });
	//fancy gallery button helper
		$(".fancybox-button").fancybox({
		prevEffect		: 'none',
		nextEffect		: 'none',
		closeBtn		: false,
		helpers		: { 
			title	: { type : 'inside' },
			buttons	: {}
		}
	});
	//fancy gallery thumbnail helper
	$(".fancybox-thumb").fancybox({
		prevEffect	: 'none',
		nextEffect	: 'none',
		helpers	: {
			title	: {
				type: 'outside'
			},
			overlay	: {
				opacity : 0.8,
				css : {
					'background-color' : '#000'
				}
			},
			thumbs	: {
				width	: 50,
				height	: 50
			}
		}
	});
	
	//texte dans la barre de recherche
	textReplacement($('#header form input[type=text]'));
	textReplacement($('.newsletter form input[type=text]'));

	/* affichage bloc press
	$('#sidebar .press .title').click(function() {
		$('#sidebar .press .content').toggle('slow');
	});
	*/
	//when the mouse pointer enters and leaves the menu fade container and footer
	$("#menu .submenu").hover(function(){
		$("#container").fadeTo("fast", 0.3);
		$("#footer").fadeTo("fast", 0.3);
		},function(){
		$("#container").fadeTo("fast", 1.0);
		$("#footer").fadeTo("fast", 1.0);
	});
	
	//lancement du slider
	$('#s3slider').s3Slider({
        timeOut: 8000
    });
	
	//place this line below fancy code
	//back to top
	$('a[href=#main]').click(function(){	$('html').animate({scrollTop:0}, 'slow'); return false; });
	//back to home
	$("a[rel=home]").click(function(){ window.location($(this).attr('href')); return false; });

/*	
	//slides the element with class "subitems" when paragraph with class "title" is clicked
    $("#leftmenu p.title").mouseover(function() {
        $(this).css({backgroundImage:"url(down.png)"}).next("div.subitems").slideToggle(300).siblings("div.menu_body").slideUp("slow");
        $(this).siblings().css({backgroundImage:"url(left.png)"});
    });
*/
});

/* fade in out to top---------------------------------------------------------*/
$(window).scroll(function(){
    posScroll = $(document).scrollTop();
    if(posScroll >=550){
		$('.scrolltotop').fadeIn(600);
		$('.scrolltoHome').fadeIn(600);
	}
	else{
		$('.scrolltotop').fadeOut(600);
		$('.scrolltoHome').fadeOut(600);
   }
});

/* textReplacement------------------------------------------------------------*/
function textReplacement(input){
   var originalvalue = input.val();
   input.focus( function(){
      if( $.trim(input.val()) === originalvalue ){ input.val(""); }
   });
   input.blur( function(){
      if( $.trim(input.val()) === "" ){ input.val(originalvalue); }
   });
}

