Cufon.replace('.page-frame-text h1', {
	fontFamily	: 'Liberation Sans',
	color		: '-linear-gradient(#838383, #181818)'
});

Cufon.replace('h3');

/************************************************************* */

//_initAjaxRequest();

$(document).ready(_initPage);

function _initPage()
{
	// centrowanie obrazow w pionie wewnatrze kontenera
	$('.vAlign').vAlign();
	// opisu pol w formularzach
	$('.clearField').clearField();
	// obrazy uruchamiane w lightboxie
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	// linki obslugiwane za pomoca XMLHTTPRequest
	//$("a[rel^='ajaxRequest']").sevEnAjaxRequest({
	//	reInitCallback	: _reinitPage
	//});

	$('.toolTip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " -=- ",
		fade: 250
	});

	$('form').submit(function(){
		$(this).clearFormArtSeven();
	});
	
	// ******************************
	
	_initCommentHover();
	_initImageRotate();
}

function _reinitPage()
{
	$('.vAlign').vAlign();
	$('.clearField').clearField();
	$("a[rel^='prettyPhoto']").prettyPhoto();

	$("a[rel^='ajaxRequest']").sevEnAjaxRequest({
		reInitCallback	: _reinitPage
	});

	$('.toolTip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " -=- ",
		fade: 250
	});

	//curvyCorners(settings, obj);
}

/************************************************************* */

function _initCommentHover()
{
	$('.box-comment').hover(function() {
		$('.content', this).css('color', '#444');
	}, function() {
		$('.content', this).css('color', '#999');
	});
}

function _initImageRotate()
{
		//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
}

/************************************************************* */

function pokazPozycje(obiektId)		{$("#" + obiektId).slideToggle("fast");}

/************************************************************* */

$(document).ready(function(){

    $('#fbspan').mouseover(function(){
        var A=$("#likeFacebook");
        var C=A.find("iframe:first");        
        if(A.hasClass("on")){A.css("width","290px").stop().animate({width:0},200,null,function(){A.removeClass("on")})}
        A.hover(function(){
           if(!A.hasClass("on")){
                A.css("width","30px").addClass("on").stop().animate({width:290},200,null);
                if(C.attr("src")==""){
                    C.attr("src","http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2F4clubberstv%2F118057451558143&amp;width=292&amp;connections=10&amp;stream=true&amp;header=false&amp;height=450")
                }
           }
        });

    });
}
);

jQuery.fn.scrollite = function(left, margin, duration) {
	margin = parseInt(margin) || 0; duration = parseInt(duration) || 0;
	return this.each(function() {
		var target = jQuery(this).css({position: 'absolute', zIndex: 10000, top: 0});
		$(window).bind('load scroll resize', function() {
			//console.log((jQuery(window).height() + (window.scrollY || window.pageYOffset || document.documentElement.scrollTop) - target.height() - margin));
			target.animate({top: (jQuery(window).height() + (window.scrollY || window.pageYOffset || document.documentElement.scrollTop) - target.height() - margin - 200) + 'px'}, duration);
		});
	});
};
$(function() {
	//$('#likeFacebook').scrollite(false, 0, 150);
});


/************************************************************* */

function _initAjaxRequest()
{
	// zastapienie funkcji w rsh
	window.dhtmlHistory.create( {
		debugMode : false,
		toJSON:		function(o) {return $.toJSON(o);},
		fromJSON:	function(s) {return $.parseJSON(s);}
	});

	window.onload = function() {
		dhtmlHistory.initialize();
		dhtmlHistory.addListener($().sevEnAjaxRequest.handleAjaxRequestHistory);
	};
}
