﻿window.addEvent('domready', function() {
	
	
	Cufon.replace($$("#menu li a, #top_menu li a, h2, h3, h4, #content.subpage .wrapper .left h5, #content.post .wrapper h5, #cloud, #bulb"), {
		fontFamily: "Times New Roman",
		hover: true
	});
	
	Cufon.replace($$("h1 .title, #register, .button"), {
		fontFamily: "Trajan Pro",
		hover: true
	});
	
	Cufon.replace($$(".more .content"), {
		fontFamily: "Myriad Pro",
		hover: true
	});
	
	Cufon.now();
	
	if($("top")){ new FadingThroughForTop($("top"), $$("#top_images img"), $$("#top_menu li"), 1000, $$("#top_images_containter_inside .content")) };
	
	if (GBrowserIsCompatible()){
		if(document.getElementById("map")){
			var map = new GMap2($("map"));
			var cords = new GLatLng(53.46330843222345, 14.543323516845703)
			
			
			map.setCenter(cords, 15);
			map.setUIToDefault();
			
			var marker = new GMarker(cords);

			marker.openInfoWindowHtml("<strong>ARA</strong><br />Duńska 27a, Szczecin 71-795");
			map.addOverlay(marker);	
		}
	}
	
	if($("register_form")){
		if($$(".wpcf7-response-output")[0]){
			var output = $$(".wpcf7-response-output")[0].clone();
			$$(".wpcf7-form")[0].grab(output, "top");
		}
	}
});


var Rotating = new Class({
						 
	initialize: function(elements, time){
		this.elements = elements;
		this.current_el = 0;
		this.time = time;
	},
	
	to_forward: function(){
		var old_current_el = this.current_el;
		if(this.current_el==this.elements.length-1){
			this.current_el = 0;
		}
		else {
			this.current_el+=1;
		}
		
		this.rotate(old_current_el, this.current_el);
	},
	
	to_backward: function(){
		var old_current_el = this.current_el;
		if(this.current_el==0){
			this.current_el = this.elements.length-1;
		}
		else {
			this.current_el-=1;
		}
		
		this.rotate(old_current_el, this.current_el);
	}
});

var FadingThroughForTop = new Class({
	Extends: Rotating,
	initialize: function(main, elements, triggers, time, contents){
		this.parent(elements, time);
		
		this.main = main;
		this.triggers = triggers;
		this.contents = contents;
		
		this.triggers.removeClass("active");
		this.triggers[0].addClass("active");
		this.elements.fade("hide");
		this.elements[0].fade("show");
		this.contents.fade("hide");
		this.contents[0].fade("show");
		
		Cufon.refresh();
		
		this.add_events();		
	},
	
	add_events: function(){
		var oThis = this;
		this.triggers.each(function(el, index){
			el.addEvent("mouseover", function(event){
				var event = new Event(event);
				event.preventDefault();
				oThis.set_element(index);
			});
		});
		
	},
	
	rotate: function(old_current_el, new_current_el){
		this.elements[old_current_el].fade("out");
		this.elements[new_current_el].fade("in");
		this.triggers.removeClass("active");
		this.triggers[new_current_el].addClass("active");
		this.contents[old_current_el].fade("out");
		this.contents[new_current_el].fade("in");
		
		Cufon.refresh();
	},
	
	set_element: function(index){
		this.rotate(this.current_el, index);
		this.current_el = index;
	}
	
});


