jQuery(document).ready(function(){
	
	function prati() {
		var formula = ($('#flash_holder').width() - $('#flash').width())/2;
		$('#flash').css({'left': formula + 'px'});
	}
	window.onresize = function(event) {
		prati();
	}
	prati();
				
	jQuery('#navigation a[href$=danos-%d0%bc%d0%b5%d0%b6%d0%b4%d1%83%d0%bd%d0%b0%d1%80%d0%be%d0%b4%d0%bd%d1%8b%d0%b5-%d0%ba%d0%be%d0%bd%d1%81%d1%83%d0%bb%d1%8c%d1%82%d0%b0%d0%bd%d1%82%d1%8b]').each( function() {
		$(this).html('<img src="http://www.danos.rs/wp-content/themes/DanosCompany/images/russian_flag.jpg" />&nbsp;' + $(this).html());
	});
	
    if(window.location.pathname.indexOf('danos-%d0%bc%d0%b5%d0%b6%d0%b4%d1%83%d0%bd%d0%b0%d1%80%d0%be%d0%b4%d0%bd%d1%8b%d0%b5-%d0%ba%d0%be%d0%bd%d1%81%d1%83%d0%bb%d1%8c%d1%82%d0%b0%d0%bd%d1%82%d1%8b') >= 0)
		jQuery('#subRight > h2').addClass('russian_title');

	$('.radio', '.image-rb').click( function() { $(this).parents('.image-rb').find('.radio').removeClass('active').addClass('inactive'); $(this).removeClass('inactive').addClass('active'); });
	$('.checkbox', '.image-cb').click( function() { 
		$(this).toggleClass('active inactive'); 
		if($(this).parents('.image-cb').find('.checkbox.active').length == 0)
			$(this).parents('.image-cb').find('div.checkbox[id!="' + $(this).attr('id') + '"]:first').toggleClass('active inactive');
	});
	
	$("#navigation").children("li:last").attr("id", "borderLeftN");
	$("#navigation").children("li:first").attr("id", "borderRightN").addClass("firstNavP");
	$("#navigation").find("ul").each( function() { $(this).children("li:last").addClass("bottomB").css("border-bottom", "none"); });	
	
	var h = parseInt($("#subRight").height()) - 300;
	$("#shadow2").height(h > 300 ? h : 300);
//	$("#shadow2").css({
//		'background-image' : $("#shadow2").css('background-image')
//	});
	
	
	jQuery('#navigation').superfish({
		delay:       200,
		animation:   {'marginLeft':'0px',opacity:'show',height:'show'},
		speed:       200,
		autoArrows:  true,
		dropShadows: false
	});
	

	$('#bnpTop').click(function() {
		if ($('#bnpMap .bnpContent').is(":hidden"))
		{
			$('#bnpMap .bnpContent').slideDown("slow");
			$('#bnpMap .bnpContentMap').slideUp("slow");
		} else {
			$('#bnpMap .bnpContent').slideUp("slow");
		}
		return false;
	})
	
	$('#bnpSecond').click(function() {
		if ($('#bnpMap .bnpContentMap').is(":hidden"))
		{
			$('#bnpMap .bnpContentMap').slideDown("slow");
			$('#bnpMap .bnpContent').slideUp("slow");
		} else {
			$('#bnpMap .bnpContentMap').slideUp("slow");
		}
		return false;
	})
	
	$('.bnpContentMap').hide();
	
	$('ul#belgrade_team .person').toggle(
		function() {
			$(this).next().find('li').stop(true, true).show(500);
		},
		function() {
			$(this).next().find('li').stop(true, true).hide(500);
		}
	);
	$('ul#references_slide li div.person').toggle(
		function() {
			$(this).siblings('ul').slideDown(500);
		},
		function() {
			$(this).siblings('ul').slideUp(500);
		}
	);
	$('ul#references_slide li ul').slideUp(1);
	
	$("#findProperty").hover( function () { $("#findProperty2").show(); }, function () { $("#findProperty2").hide(); });
	
	// SLIDER INDEX NEWS SLIDER INDEX NEWS // SLIDER INDEX NEWS SLIDER INDEX NEWS // SLIDER INDEX NEWS SLIDER INDEX NEWS
	jQuery('ol#index_news_slider li').clone().appendTo('ol#index_news_slider');	
});

// SLIDER INDEX NEWS SLIDER INDEX NEWS
var tim;
var news_count = 0;
var li_sum = 10;
var news_time = 4000;

function slider_index_news(){
	if(jQuery('ol#index_news_slider').hasClass('working'))
		return;
	
	jQuery('ol#index_news_slider').addClass('working');
	
	news_count++;
	
	jQuery('ol#index_news_slider').animate({
		top: '-=95'
	  }, 500,  function(){									  
					if(news_count >= li_sum) {
						news_count = 0;						
						jQuery('ol#index_news_slider').css({top: 0});
					}	
					jQuery('ol#index_news_slider').removeClass('working');
				} 
	);
	
	tim = setTimeout("slider_index_news()", news_time);
}
tim = setTimeout("slider_index_news()", news_time);
//REVERSE SLIDER NEWS INDEX
/*
function slider_index_news(){
	if(jQuery('ol#index_news_slider').hasClass('working'))
		return;
	
	jQuery('ol#index_news_slider').addClass('working');
	news_count--;

	if(news_count < 0) {
		news_count += li_sum;
		jQuery('ol#index_news_slider').css({top: -95*li_sum});
	}	
	jQuery('ol#index_news_slider').animate({
		top: '+=95'
	  }, 500, function() {	
			$('ol#index_news_slider').removeClass('working');
		  } );
		
	tim = setTimeout("slider_index_news()", news_time);
}
tim = setTimeout("slider_index_news()", news_time);
*/

function sendMailRequest(url, from, to, subject, content, buttonid, mesageid)
{
	var params = 'from=' + from + '&to=' + to + '&subject=' + subject + '&content=' + content;
	
	xmlhttp = GetXmlHttpObject();
	xmlhttp.onreadystatechange = function() {if (xmlhttp.readyState == 4)
											{
												if(xmlhttp.responseText.indexOf('mailsentok') >= 0)
												{
													$(mesageid).html('Message sent.');
													//$('#' + succesid).show();
												}
												else
												{
													$(mesageid).html('Error sending message.');
													$(buttonid).show();									
												}
											}
										};
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	$(buttonid).hide();
	$(mesageid).html('Sending message...');
}

function getSharePrice(url, id, timeid, priceid, changeid, high_id, low_id)
{
	xmlhttp = GetXmlHttpObject();
	xmlhttp.onreadystatechange = function() {if (xmlhttp.readyState == 4)
											{												
												try {
													var elements = xmlhttp.responseText.split("|");
													if(elements.length >= 6 && elements[0] == "ok")
													{
														jQuery("#" + priceid).html(elements[1]).wrapInner("<strong>");
														jQuery("#" + timeid).html(elements[2]);
														jQuery("#" + changeid).html(elements[3]).wrapInner("<strong>");
														jQuery("#" + high_id).html(elements[4]);
														jQuery("#" + low_id).html(elements[5]);
														jQuery("#" + id).slideDown();
													}
													else
													{
														jQuery("#" + id).html("No data available.").show();
													}
												}
												catch(e)
												{
													jQuery("#" + id).html("No data available.").show();
												}
											}
										};
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}


