jQuery.noConflict();



jQuery(document).ready(

	function($)

	{

		

		$(".city").hover(

				function() {

					element = $(this).attr('id');

					id = element.substring(5);

					$(this).addClass('bold');

					$('#point'+id).addClass('redPoint');

				},

				function() {

					$(this).removeClass('bold');

					$('#point'+id).removeClass('redPoint');

				}

		);

		

		$(".left, .right").hover(

				function() {

					element = $(this).attr('id');

					id = element.substring(5);

					$(this).addClass('redPoint');

					$('#city_'+id).addClass('bold');

				},

				function() {

					$(this).removeClass('redPoint');

					$('#city_'+id).removeClass('bold');

				}

		);

		

		$("#regionalMap").hover(

				function() {

					$("#largeRegionalMap").fadeIn('slow');

				}

				,

				function () {

					return true;

				}

		);



		$("#largeRegionalMap").hover(

				function () {

					return true;

				}

				,

				function() {

					$("#largeRegionalMap").fadeOut('slow');

				}

		);



		$("#close").click(

				function () {

					$("#largeRegionalMap").fadeOut('slow');

				}

		);

		$(".sendArticle").bind(
				'click',
				function() {
					$('#sendArticleBox').show();
				}
		);
		
		$(".sendArticleClose").bind(
				'click',
				function() {
					$('#sendArticleBox').hide();
				}
		);
		$('#sendArticleSubmit').bind(
			'click',
			function() {
				var hasError = false;
				
				$("#sendArtNameH").removeClass("error");
				var nameVal = $("#sendArtName").val();
				if(nameVal == '') {
					$("#sendArtNameH").addClass("error");
					hasError = true;
				}
				
								
				$("#sendArtDestH").removeClass("error");
				var destVal = $("#sendArtDest").val();
				if(destVal == '') {
					$("#sendArtDestH").addClass("error");
					hasError = true;
				} 

				
				if(hasError == true) {
					scroll(0,150);
					//alert("Iiey, iiiueiaoa ane?ee iieaoa ioaaeycaie n ?a?aaii e i?iaa?aoa aaeeaiinooa ia auaaaaiey E-mail aa?an!");
					alert("Моля попълнете полетата в червено!");

				}
				
				if(hasError == false) {
					
					$.post("/ajax/ajax_send_article.php",
					   { 
						name: $("#sendArtName").val(),
						destination: $("#sendArtDest").val(),
						text: $("#sendArticleText").val(),
					   },
					   	function(result) {
						   //alert(result);
						  	if(result == 'true') {
						  		$('#sendArticleForm').hide();
						  		$('#sendArticleSent').show();
							}
						  	else {
						  		$("#captchaText").addClass("error");
							}
						  	
						}
					);
				}
			}	
		);
		

		

	}

);


function showGWindowOnList(e, url, wth, hth, bing) {

    // functions from interactivemap.js
   /* try {    
        var start = url.toString().indexOf("apts=",0)+5;
        var end = url.toString().indexOf("&c=",start);
        var aptid = url.toString().slice(start,end);
        MapEngine.ShowMap(e, aptid);
        e.returnValue=false;
        return false;
    } catch (excia) {}*/
    if (!e) e = window.event;

    var posx = 0;
    var posy = 0;
    if (e.pageX || e.pageY) {
        posx = e.pageX-800;
        posy = e.pageY-185;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft-800;
        posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop-185;
    }/**/

    var elem = document.getElementById('ratingsWindow');

  //  posx -= elem.offsetWidth;
    //posy -= elem.offsetHeight;

    if (posx + elem.offsetWidth > document.body.offsetWidth)
        posx = document.body.offsetWidth - elem.offsetWidth;
    if (posy + elem.offsetHeight > document.body.offsetHeight)
        posy = document.body.offsetHeight - elem.offsetHeight;

    elem.style.visibility = 'visible';
    elem.style.left = (posx) + 'px';
    elem.style.top = (posy) + 'px'; 

    elem.style.width = wth + 'px';
    elem.style.height = 15 + parseInt(hth) + 'px';
    elem.style.borderBottomStyle = "solid";
    elem.style.borderBottomWidth = "1px";

   // document.getElementById("bing").style.display = 'block';
  //  document.getElementById("bing").children[0].href = "javascript:MapWindow('" + bing + "')";
       
    window.frames["ifRatings"].location = url;
    document.getElementById("ifRatings").width = parseInt(wth);
    document.getElementById("ifRatings").height = parseInt(hth);
}

function hideWindow() {

    document.getElementById('ratingsWindow').style.visibility = 'hidden';
    window.frames["ifRatings"].location = 'about:blank';
    try {
        // RemoveEvent(window.document, 'click', hideWindow);
    } catch (err1) { }

}

var moving = false;
var offX = 0;
var offY = 0;

function setWindowPos(e) {
    if (!moving) return;
    if (!e) e = window.event;

    var elem = document.getElementById('ratingsWindow');
    elem.style.left = e.clientX - offX + 'px';
    elem.style.top = e.clientY - offY + 'px';
}

function lockWindow(e) {
    var elem = document.getElementById('ratingsWindow');
    offX = e.clientX - elem.offsetLeft;
    offY = e.clientY - elem.offsetTop;

    moving = true;
    document.onmousemove = setWindowPos;
    document.onmouseup = unlockWindow;
}

function unlockWindow() {
    moving = false;
    document.onmousemove = null;
    document.onmouseup = null;
}

function MapWindow(mypage) {
    var win = null;
    var w = 800;
    var h = 600;
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    myname = "MAP";

    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no, resizable=yes';
    win = window.open('', myname, settings);
    win.location.href = mypage;
    //win.onload = sc;
    //window.scrollTo(0,500);
}

function FitWindow(mypage) {    
    myname = "MAP";

    settings = 'height=' + screen.height + ',width=' + screen.width + ',scrollbars=no, resizable=yes';
    win = window.open('', myname, settings);
    mypage = mypage.toString().replace('mapwidth=0', 'mapwidth='+ screen.width);
    mypage = mypage.toString().replace('mapheight=0', 'mapheight='+ screen.height);
    win.location.href = mypage;
}


