//Overwrite findChildElements to use Sizzle http://sizzlejs.com
Selector.findChildElements = function(element, expression){
    expression = expression.join(", ");
    var results = Sizzle(expression, element);
    if(results.length > 0){
        for(var i=0; i < results.length; i++){
            results[i] = Element.extend(results[i]);
        }
    }
    return results;
};

Event.observe(window, 'load', function() {
	//MENU STOPKA
	$$('ul#bottom_menu li a span').each(function(item) {
		item.setStyle({opacity:0});
		item.observe('mouseover', function(e) { e.stop(); item.style.opacity = 0; new Effect.Opacity(item, {duration:0.7, from:0.0, to:1});/*this.com_open_link_multimedia(item.href);*/ }.bind(this) );
		item.observe('mouseout', function(e) { e.stop(); item.style.opacity = 1; new Effect.Opacity(item, {duration:0.7, from:1, to:0.0});/*this.com_open_link_multimedia(item.href);*/ }.bind(this) );
	  }.bind(this)
	);

	$$('.right_cont_col a span').each(function(item) {
		item.setStyle({opacity:0});
		item.observe('mouseover', function(e) { e.stop(); item.style.opacity = 0;  new Effect.Opacity(item, {duration:0.7, from:0.0, to:1});/*this.com_open_link_multimedia(item.href);*/ }.bind(this) );
		item.observe('mouseout', function(e) { e.stop(); item.style.opacity = 1; new Effect.Opacity(item, {duration:0.7, from:1, to:0.0});/*this.com_open_link_multimedia(item.href);*/ }.bind(this) );
	  }.bind(this)
	);

	var	dd_effect	= false;
	$('quick_gal_big_photo').observe('mouseover', function(item) {  
		if (dd_effect !== false) dd_effect.cancel();
		if (current_Gal_ID_null_details_hov == false) dd_effect = new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 300, mode: 'absolute' });
	}.bind(this) );
	$('quick_gal_big_photo').observe('mouseout', function(item) { 
		if (dd_effect !== false) dd_effect.cancel();
		dd_effect = new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });
	}.bind(this) );
	
});  

jQuery(function () {
  if (jQuery.browser.msie && jQuery.browser.version < 7) return;
  jQuery('#top_menu li')
    // within the context of the li element, find the a elements
    .find('a span').each(function () {
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var jQueryspan = jQuery(this).css('opacity', 0);
      // when the user hovers in and out of the anchor
      jQuery(this).hover(function () {
        // on hover
        // stop any animations currently running, and fade to opacity: 1
        jQueryspan.stop().fadeTo(350, 1);
      }, function () {
        // off hover
        // again, stop any animations currently running, and fade out
        jQueryspan.stop().fadeTo(350, 0);
      });
    });
});
//jQuerry odpowiedzialne za dolne menu social media
jQuery(function () {
  if (jQuery.browser.msie && jQuery.browser.version < 7) return;
  jQuery('#bottom_menu2 li')
    // within the context of the li element, find the a elements
    .find('a span').each(function () {
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var jQueryspan = jQuery(this).css('opacity', 0);
      // when the user hovers in and out of the anchor
      jQuery(this).hover(function () {
        // on hover
        // stop any animations currently running, and fade to opacity: 1
        jQueryspan.stop().fadeTo(500, 1);
      }, function () {
        // off hover
        // again, stop any animations currently running, and fade out
        jQueryspan.stop().fadeTo(500, 0);
      });
    });
});



function viewPort_dim() {
	var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
	var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
	return { width : w , height : h }
}

function viewPort_resize(){
	var vp_width = viewPort_dim().width;
	var vp_height = viewPort_dim().height;
	
	$('skin_above').setStyle({'height':''+vp_height+'px'});
}

function resize(){  
	//var frame = document.getElementById("frame1");  
	var htmlheight = document.body.parentNode.scrollHeight;  
	var windowheight = window.innerHeight;  
	if ( htmlheight < windowheight ) { 
		document.body.style.height = windowheight + "px"; $('skin_above').style.height = windowheight + "px";
	} else { 
		document.body.style.height = htmlheight + "px"; $('skin_above').style.height = htmlheight + "px";
	}
	
	//middle_content_div
	//miarka_middle_div
	//alert( $('middle_content_div').scrollHeight);
	$('miarka_middle_div').style.height = $('middle_content_div').scrollHeight + 'px';
	$('miarka_bg').style.height  = $('middle_content_div').scrollHeight + 70 + 'px';
} 

function getXY2(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
	$('miarka_bg').setStyle({backgroundPosition: '0px '+cursor.y+'px'});	
    //return cursor;
}

//window.onload = init;
function init_cursor() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
  x = (window.Event) ? e.pageX : event.clientX;
  y = (window.Event) ? e.pageY : event.clientY;

	$('miarka_bg').setStyle({backgroundPosition: '0px '+y+'px'});	
  //document.ee.sd.value = x+":"+y;
}

function animate_LINE(){$('miarka_bg').setStyle({backgroundPosition: '0px 0px'});}

function initOneFitness(){
	//viewPort_resize();	
	resize();
	init_cursor();
	//Event.observe(window, 'resize', function() { viewPort_resize() });
	Event.observe(window, 'resize', function() { resize() });
}



function open_login_window(el){
	if ($('abs_login_window').getStyle('display') == 'none'){
		//el.toggleClassName('roll_out');
		el.removeClassName('roll_in');
		el.addClassName('roll_out');
		new Effect.Morph('menu_main', {style: 'margin-top:80px;',duration: 0.8});
		$('abs_login_window').setStyle({'top':'39px','left':'-24px'});
		new Effect.Grow('abs_login_window', {direction : 'top-right',duration: 0.8});
		//$('abs_login_window').show();
		
	} else {
		//el.toggleClassName('roll_in');
		el.removeClassName('roll_out');
		el.addClassName('roll_in');
		new Effect.Morph('menu_main', {style: 'margin-top:0px;',duration: 0.8});
		new Effect.Shrink('abs_login_window', {direction : 'top-right',duration: 0.8});
		//$('abs_login_window').hide();
			
	}
}

function open_chooser_window(){
	if ($('choose_club_div').getStyle('display') == 'none'){
		//el.toggleClassName('roll_out');
		//el.removeClassName('roll_in');
		//el.addClassName('roll_out');
		//new Effect.Morph('menu_main', {style: 'margin-top:80px;',duration: 0.8});
		$('choose_club_div').setStyle({'top':'72px','left':'4px'});
		//new Effect.Grow('choose_club_div', {direction : 'top-right',duration: 0.8});
		new Effect.Grow('choose_club_div', {direction : 'top-left',duration: 0.8});
		//$('abs_login_window').show();
		
	} else {
		//el.toggleClassName('roll_in');
		//el.removeClassName('roll_out');
		//el.addClassName('roll_in');
		//new Effect.Morph('menu_main', {style: 'margin-top:0px;',duration: 0.8});
		//new Effect.Shrink('choose_club_div', {direction : 'top-right',duration: 0.8});
		new Effect.Shrink('choose_club_div', {direction : 'top-left',duration: 0.8});
		//$('abs_login_window').hide();
			
	}
}


function show_quick_gall(){
	var div_arrow_left = $$('a.arrow_left')[0];
	var div_arrow_right = $$('a.arrow_right')[0];
	
	$('bg_fade_descr').setStyle({'top':'400px'});
	$('quick_gallery').setStyle({overflow:'hidden', height:'0px'});
	$('quick_gallery').show();
	//new Effect.Morph('cont_btn_open_gal', {style: 'opacity:0;',duration: 0.8});
	$('cont_btn_open_gal').fade({ duration: 0.8, from: 1, to: 0 });
	new Effect.Morph('quick_gallery', {style: 'height:450px;',duration: 0.8});
	setTimeout(function(){$('quick_gallery').setStyle({overflow:'visible'}) },800);
	
	$$('a.arrow_left')[0].setStyle({top:'8px', left:'-1000px'});
	setTimeout(function(){div_arrow_left.show() },100);
	setTimeout(function(){new Effect.Move(div_arrow_left, { x: -15, y: 8, mode: 'absolute' })},100);
	
	$$('a.arrow_right')[0].setStyle({top:'8px', left:'+2000px'});
	setTimeout(function(){div_arrow_right.show() },100);
	setTimeout(function(){new Effect.Move(div_arrow_right, { x: 707, y: 8, mode: 'absolute' })},100);	
	setTimeout(function(){resize();},900);

	setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 300, mode: 'absolute' });},800);	
	super_Gal(1);
	//setTimeout(function(){ new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 400, mode: 'absolute' });},800);
	//new Effect.Move($('bg_fade_descr'), { duration:0.5, x: 0, y: 300, mode: 'absolute' });	
	//setTimeout(function(){$('cont_btn_open_gal').setStyle({display:'none'}); },900);
	
	//setTimeout(function(){$$('a.arrow_left')[0].show() },1800);
	//Effect.BlindDown($$('a.arrow_left'), { duration: 3.0, scaleX: true, scaleY:false });
}

function hide_quick_gall(){
	var div_arrow_left = $$('a.arrow_left')[0];
	var div_arrow_right = $$('a.arrow_right')[0];	
	
	$('quick_gallery').setStyle({overflow:'hidden'});
	new Effect.Morph('quick_gallery', {style: 'height:0px;',duration: 0.8});
	//setTimeout(function(){$('quick_gallery').setStyle({overflow:'visible'}) },800);
	
	//$$('a.arrow_left')[0].setStyle({top:'8px', left:'-15px'});
	setTimeout(function(){div_arrow_left.show() },100);
	setTimeout(function(){new Effect.Move(div_arrow_left, { x: -1000, y: 8, mode: 'absolute' })},100);
	
	//$$('a.arrow_right')[0].setStyle({top:'8px', left:'707px'});
	setTimeout(function(){div_arrow_right.show() },100);
	setTimeout(function(){new Effect.Move(div_arrow_right, { x: 2000, y: 8, mode: 'absolute' })},100);	

	$('cont_btn_open_gal').appear({ duration: 0.8, from: 0, to: 1 });
	//new Effect.Morph('cont_btn_open_gal', {style: 'opacity:100;',duration: 0.8});
	//setTimeout(function(){$('cont_btn_open_gal').setStyle({display:'block'}); },800);
	setTimeout(function(){$('quick_gallery').hide() },900);
	setTimeout(function(){resize();},900);
	setTimeout(function(){$('bg_fade_descr').setStyle({'top':'400px'})}, 900);
}





