jQuery.noConflict();

jQuery( document ).ready( function() {
	//tooltip();
	if( jQuery( '#gmap' ).length != 0 ) {
		jQuery( '#gmap' ).css({ width: '574px', height: '550px' });
		jQuery( 'body' ).load( initializeGMap() );
		//jQuery( 'body' ).unload( GUnload() );
		
		jQuery( 'a.contactLink' ).click( function() {
			addAddressToMap( jQuery( this ).attr( 'rel' ) );
		});
	}
	jQuery( '.h-menu .rel' ).hover(
		function() {
			jQuery(this).addClass( 'act' );
			//jQuery(this).find('.sub-menu0').slideDown(100);
		},
		function() {
			jQuery(this).removeClass( 'act' );
			//jQuery(this).find('.sub-menu0').slideUp(100);
		}
	);
	jQuery( '.ml_tit' ).click( function () 
	{
		var a = jQuery( this ).next( '.l-sub' );
		if ( a.parent( 'li:first' ).hasClass( 'act' ) ) {
			
		} else {
			jQuery( '.l-sub' ).parent( 'li:first' ).removeClass( 'act' );
			jQuery( '.l-sub' ).removeClass( 'lm_opened' ).slideUp( 200 );
		}

		jQuery( '.l-menu li' ).removeClass( 'act' );

		if ( a.hasClass( 'lm_opened' ) ) {
			a.parent( 'li:first' ).removeClass( 'act' );
			a.removeClass( 'lm_opened' ).slideUp( 200 );
		} else {
			a.parent( 'li:first' ).addClass( 'act' );
			a.addClass( 'lm_opened' ).slideDown( 200 );
		}
	});
	if( jQuery( '#proj_imgs' ).length != 0 ) {
		/* jQuery( 'td.bk-pics-l, td.bk-pics-r' ).hover(
			function() {
				var imgs = jQuery( this ).attr( 'rel' );
				imgs = imgs.split( ',');
				jQuery( this ).css({
					background: 		'url( "'+imgs[1]+'" )',
					backgroundRepeat: 	'no-repeat'
				});
				if( jQuery( this ).attr( 'class' ) == 'bk-pics-l' ) jQuery( this ).css( 'background-position', 'right 0' );
			},
			function() {
				var imgs = jQuery( this ).attr( 'rel' );
				imgs = imgs.split( ',');
				jQuery( this ).css({
					background: 		'url( "'+imgs[0]+'" )',
					backgroundRepeat: 	'no-repeat'
				});
				if( jQuery( this ).attr( 'class' ) == 'bk-pics-l' ) jQuery( this ).css( 'background-position', 'right 0' );
			}
		); */
		var imgsl = jQuery( 'td.bk-pics-l' ).attr( 'rel' );
		var imgsr = jQuery( 'td.bk-pics-r' ).attr( 'rel' );
		imgsl = imgsl.split( ',');
		imgsr = imgsr.split( ',');
		jQuery( 'div.grey-round' ).hover(
			function() {
				if( jQuery( this ).attr( 'class' ) == 'grey-round grey-round-l' ) {
					jQuery( 'td.bk-pics-l' ).animate( { opacity: "0.7" }, 200 )
											.css({
												background: 		'url( "'+imgsl[1]+'" )',
												backgroundRepeat: 	'no-repeat',
												backgroundPosition: 'right 0'
											})
											.animate( { opacity: "1" }, 200 );
				}
				if( jQuery( this ).attr( 'class' ) == 'grey-round grey-round-r' ) {
					jQuery( 'td.bk-pics-r' ).animate( { opacity: "0.7" }, 200 )
											.css({
												background: 		'url( "'+imgsr[1]+'" )',
												backgroundRepeat: 	'no-repeat'
											})
											.animate( { opacity: "1" }, 200 );
				}
			},
			function() {
				if( jQuery( this ).attr( 'class' ) == 'grey-round grey-round-l' ) {
					jQuery( 'td.bk-pics-l' ).animate( { opacity: "0.7" }, 200 )
											.css({
												background: 		'url( "'+imgsl[0]+'" )',
												backgroundRepeat: 	'no-repeat',
												backgroundPosition: 'right 0'
											})
											.animate( { opacity: "1" }, 200 );
				}
				if( jQuery( this ).attr( 'class' ) == 'grey-round grey-round-r' ) {
					jQuery( 'td.bk-pics-r' ).animate( { opacity: "0.7" }, 200 )
											.css({
												background: 		'url( "'+imgsr[0]+'" )',
												backgroundRepeat: 	'no-repeat'
											})
											.animate( { opacity: "1" }, 200 );
				}
			}
		);
	}
	if( jQuery( 'td.f-info' ).length != 0 ) {
		var contacts = '';
		jQuery.getJSON(
			'http://www.geoplugin.net/json.gp?jsoncallback=?',
			function( data ) {
				switch( data.geoplugin_region ) {
					case 'Moscow':
						contacts = 'Адрес: Москва, Новорязанская улица, 31/7, корпус 1.<br />';
						contacts += 'Тел./факс: +7 (495) 775-0055<br />';
						contacts += 'Факс: +7 (495) 261-9040';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Novosibirsk':
						contacts = 'Адрес: 630007 г. Новосибирск, ул. Коммунистическая, 50<br />';
						contacts += 'Тел./факс: (383) 218-10-54, 218-79-70';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Ekaterinburg':
						contacts = 'Адрес: г. Екатеринбург, пл. Жуковского, д. 1<br />';
						contacts += 'Тел./факс: (343) 213-3133, 216-1671';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Voronezh':
						contacts = 'Адрес: г. Воронеж, ул. Витрука, 10А<br />';
						contacts += 'Тел./факс: (4732) 396-222';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Irkutsk':
						contacts = 'Адрес: г. Иркутск, ул. Полярная, 77<br />';
						contacts += 'Тел./факс: (3952) 780-250';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Kazan':
						contacts = 'Адрес: 420107 г. Казань, ул. Островского, 87, офис 405<br />';
						contacts += 'Тел./факс: (843) 292-83-69, 292-89-66';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Habarovsk':
						contacts = 'Адрес: 680015, г. Хабаровск, ул. Сидоренко, 7<br />';
						contacts += 'Тел./факс: (4212) 59-06-01, 59-05-99';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Samara':
						contacts = 'Адрес: 443044, г.Самара, ул.Санфировой, 95, оф.520 <br />';
						contacts += 'Тел./факс: (846) 222-90-65';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Sochi':
						contacts = 'Адрес: 354000, г. Сочи, ул. Черноморская, 15, оф.12<br />';
						contacts += 'Тел./факс: (8622) 901-653, 901-654';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'St. Petersburg':
						contacts = 'Адрес: 195027, Санкт-Петербург, Среднеохтинский проспект, д. 11,кор.1<br />';
						contacts += 'Тел./факс:  (812) 248-3424';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Tyumen':
						contacts = 'Адрес: 625014, г. Тюмень, 11 км Ялуторовского тракта, д.5,стр.1<br />';
						contacts += 'Тел./факс: (3452) 490-300';
						jQuery( 'td.f-info' ).html( contacts );
						break;
					case 'Yaroslavl':
						contacts = 'Адрес: 150044, г. Ярославль, ул. Промышленное шоссе, д.60<br />';
						contacts += 'Тел./факс: (4852) 55-46-46, 55-47-47';
						jQuery( 'td.f-info' ).html( contacts );
						break;
				}
			});
	}
});

var map;
var markerOptions;

function initializeGMap() {
	map = new GMap2(document.getElementById("gmap"));
	map.setUIToDefault();
	
	var baseIcon = new GIcon();
	baseIcon.shadow 		  = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize 	  	  = new GSize(32, 32);
	baseIcon.shadowSize 	  = new GSize(37, 32);
	baseIcon.iconAnchor 	  = new GPoint(9, 32);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	var letteredIcon   = new GIcon(baseIcon);
	letteredIcon.image = "/upload/img/templates/logo.png";
	markerOptions = { icon:letteredIcon };
	
	addAddressToMap( jQuery( 'a.contactLink:first' ).attr( 'rel' ) );
}

function addAddressToMap(points) {
	map.clearOverlays();
	points = points.split( ',' );
	point = new GLatLng(points[1], points[2]);
	marker = new GMarker(point, markerOptions);
	map.addOverlay(marker);
	map.setCenter(new GLatLng(points[1], points[2]), 16);
	marker.openInfoWindowHtml( '<div class="contactInfoWindow">'+jQuery( '#contact-'+points[0]+' div.contactText' ).html()+'</div>' );
}

this.tooltip = function(){
		xOffset = 0;
		yOffset = 20;
	jQuery("a.tooltip").hover(function(e){
		this.t     = this.title;
		this.title = "";
		
		jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		jQuery("#tooltip").remove();
    });
	jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};