//embediing main page flash movie
var flashvars = {};
/*
flashvars.link01 = "/it";
flashvars.link02 = "/cinema";
flashvars.link03 = "/sewage";
flashvars.link04 = "/engineer";
*/
var params = {};
var attributes = {};
swfobject.embedSWF("/swf/intro.swf", "flashMovieContainer", "1000", "600", "9.0.0", false, flashvars, params, attributes);

//embediing how it works flash movie
swfobject.embedSWF("/swf/how_it_works.swf", "sewageDescFlashContainer", "384", "528", "9.0.0", false, {}, {}, {});



$(document).ready(function(){
	
	//dynamic loading of google map functionality
	var mapContainer = $("#ibqlOfficeLocation");
	if (mapContainer.length) {
		google.load("maps", "2", {
			callback : function(){
				new GoogleMap(mapContainer);
			},
			language: "ru"
		});
	}
	
	
	
	// teaser on the  /sewage/description page
	$("#teaserSlider").cycle({
		fx:      'scrollLeft',
    	speed:    300, 
    	timeout:  5500 
	})
	
	// add to fav link
	$("a.addToFavourites").click(function(){
		return false;
	})
	
	// converting all mail links to real email ones
	$("a.mail").each(function(){
		var jMailLink = $(this);
		jMailLink.text(jMailLink.text() + "@ibql.ru")
		jMailLink.attr("href", "mailto:" + jMailLink.text());
	})
	
	//sewage advantages list located at /sewage/description page
	var resellerCitiesLinks = $("#where2buy .listOfCities > li > h2 > a");
	var resellerCitiesDetails = $("#where2buy .listOfCities > li > .itemDetails");
	resellerCitiesLinks.each(function(i){
		var jAdvLink = $(this);
		var details = jAdvLink.parent().next();
		jAdvLink.click(function(){
			resellerCitiesDetails.slideUp();
			resellerCitiesLinks.filter(function(j){ return i != j; }).removeClass("current");
			jAdvLink.toggleClass("current");
			details[jAdvLink.hasClass("current") ? "slideDown" : "slideUp"]();
			
			return false;
		})
	})
		
	//reseller points list located at /sewage/where2buy page
	var sewageAdvantagesLinks = $("#sewageDescDetails .ibqlSewageAdvantages > li > h2 > a");
	var sewageAdvantagesDetails = $("#sewageDescDetails .ibqlSewageAdvantages > li > .itemDetails");
	sewageAdvantagesLinks.each(function(i){
		var jAdvLink = $(this);
		var details = jAdvLink.parent().next();
		jAdvLink.click(function(){
			sewageAdvantagesDetails.slideUp();
			sewageAdvantagesLinks.filter(function(j){ return i != j; }).removeClass("current");
			jAdvLink.toggleClass("current");
			details[jAdvLink.hasClass("current") ? "slideDown" : "slideUp"]();
			
			return false;
		})
	})
	
	//photo gallery interaction
	var photoGalleries = $("#content  .optionalContent  .photoGallery");
	if (photoGalleries.length) {
		photoGalleries.each(function(){
			var gallery = $(this);
			var photoGalleryItems = gallery.find("li > a");
			var photoTooltip = gallery.next().children("p");
			var initialText = photoTooltip.html(); 
			photoGalleryItems.lightBox({txtImage: ""});
			photoGalleryItems.each(function(){
				var jItem = $(this);
				var title = this.title;
				jItem.mouseover(function(){
					photoTooltip.text(title)
				})
				jItem.mouseout(function(){
					photoTooltip.empty().append(initialText)
				})
						
			})
		})
	}
	
	//sewage descriptions switcher
	initTabs({ 
		tabs: $("#sewageDescription > ul.sewageDescTabs > li > a"),
		containers: $("#sewageDescDetails .sewageDescContainer")
	})

	//sewage versions switcher
	initTabs({ 
		tabs: $("#sewageArrangements > ul.versions > li > a"),
		containers: $("#sewageArrangements .versionDesc")
	})
	
	//sewage installation steps switcher
	initTabs({ 
		tabs: $("#sewageInstallationSteps > .steps li > a"),
		containers: $("#sewageInstallationSteps .stepDiscription")
	})
	
	//it conception steps switcher
	initTabs({ 
		tabs: $("#itServicesSteps > .steps li > a"),
		containers: $("#itServicesSteps .stepDiscription")
	})

	function initTabs(params) {
		if (params.tabs && params.containers) {
			params.tabs.each(function(){
				var jTab = $(this);
				var key = this.getAttribute("href", 2).substring(1);
				jTab.click(function(){
					params.tabs.removeClass("current");
					jTab.addClass("current");
					params.containers.hide();
					params.containers.filter(function(){return this.id == key}).show();				
					return false;
				})
			})
		}
	}
})

