var IE = document.all?true:false


$(document).ready(function(){

	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square',slideshow:2000, autoplay_slideshow: false,overlay_gallery: true,	show_title: false,	default_width: 704, 	markup: '<div class="pp_pic_holder"> \
		<div class="ppt">&nbsp;</div> \
		<div class="pp_top"> \
			<div class="pp_left"></div> \
			<div class="pp_middle"></div> \
			<div class="pp_right"></div> \
		</div> \
		<div class="pp_content_container"> \
			<div class="pp_left"> \
			<div class="pp_right"> \
				<div class="pp_content"> \
					<div class="pp_loaderIcon"></div> \
					<div class="pp_fade"> \
						<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
						<div class="pp_hoverContainer"> \
							<a class="pp_next" href="#">next</a> \
							<a class="pp_previous" href="#">previous</a> \
						</div> \
						<div id="pp_full_res"></div> \
						<div class="pp_details clearfix"> \
							<p class="pp_description"></p> \
							<div class="fr lGClose"><div class="aroRLink">\
								<a class="pp_close" href="#">'+_close+'</a> \
							</div></div>\
						</div> \
					</div> \
				</div> \
			</div> \
			</div> \
		</div> \
	</div> \
	<div class="pp_overlay"></div>',
gallery_markup: '<div class="pp_gallery"> \
				<a href="#" class="pp_arrow_previous">Previous</a> \
				<ul> \
					{gallery} \
				</ul> \
				<a href="#" class="pp_arrow_next">Next</a> \
			</div>',
image_markup: '<img id="fullResImage" src="" />',
flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
inline_markup: '<div class="pp_inline clearfix">{content}</div>',
custom_markup: ''});
	
	
	
	
	AutocompleteInit()

	$("#top div.Searcher a.button").toggle(function(){
		$("#top div.Searcher div.form").animate({
			right: '0px'
		},200, "swing")
		$("#top div.Searcher a.button img").css("display","block");
		$("#top div.Searcher a.button img:first-child").css("display","none");
		
	}, function(){
		$("#top div.Searcher div.form").animate({
			right: '-234px'
		},500, "swing")
		$("#top div.Searcher a.button img").css("display","block");
		$("#top div.Searcher a.button img:last-child").css("display","none");
	})
	
RealLine()
	
//	$( "#sortable" ).sortable();
//	$( "#sortable" ).disableSelection();
	$('div#NewsItem div.Gallery').jScrollPane({showArrows: true});
	
	
	//$("form#invest-enquiry .radio").dgStyle();
		$("div.news span.toggle, div.news span.title").click(
				function(){
					if($(this).parent().parent().hasClass('actNews')) {
					$(this).parent().parent().children("div.cont").slideUp();
					$(this).parent().parent().removeClass('actNews');
					}
					else {
					$(this).parent().parent().toggleClass("openNews");
					$(this).parent().parent().children("div.cont").slideToggle("slow");
					}
				}
		
		)
		$("form#invest-enquiry div.row div.right select").sb({ fixedWidth: true });
		$("form#Query div.row div.right select").sb({ fixedWidth: true });
		$("div#r-real-gal select").sb({ fixedWidth: true });
		$("div#Strenghts span.title a").click(
				function(){
					$("div#Strenghts ul, div#Strenghts ol").slideToggle('slow');
					$("div#Strenghts span.title").toggleClass('bold');
					$("div#Strenghts span.title a:first-child").clone(true).appendTo("div#Strenghts span.title");
					$("div#Strenghts span.title a:first-child").remove();
					return false;
				}
		
		)
		$("div.qMenu a[title]").tooltip({
			position: 'bottom right',
			offset: [3, -29]
		});

		var pCount = 1;
		$("div#RealizationVisualizations .scrollable").scrollable().navigator();
		$("div#RealizationVisualizations .navi a").each(function(){
			$(this).html(pCount++)
		})

		var mCount = 1;
		$("div#Maps .scrollable").scrollable().navigator({activeClass: "act"});
		$("div#MapsPages .navi a").each(function(){
			$(this).html(mCount++)
		})
		
		Cufon.replace('div#RealizationVisualizations div.navi a, div#partnerLogin label.Submit a, #menu-hld ul li a, div.Pagination a.next, div.Pagination a.prev, div#RealizationName a.references, div#RealizationsList div.Items div.Photo a.inProgress span', {
			color: '#fff'
		});		
		Cufon.replace('h1, .hTitle, div.Invest-Page div.Left div.Header span.title, div.Invest-Page div.Right div.Header, div#wide div.page-title, div#r-real-gal div.title', {
			color: '#555'
		});	
		
		
		
});

function closeAskExpert() {
	document.getElementById("AskEkspert").style.display = "none";
}

function ShowAskExpert(){
		pageS = new Array();
		pages = getPageSize();
		CommentBox = (pages[0]/2)-225+'px';
		document.getElementById('AskEkspert').style.left = CommentBox;
		if(IE)
		document.getElementById('AskEkspert').style.top = document.documentElement.scrollTop + 100 + 'px';
		else 
		document.getElementById('AskEkspert').style.top = window.pageYOffset + 100 + 'px';					
		document.getElementById('AskEkspert').style.display = "block";	
}


function getPageSize(){
	  var xScroll, yScroll;
	  if (window.innerHeight && window.scrollMaxY) {
	     xScroll = document.body.scrollWidth;
	     yScroll = window.innerHeight + window.scrollMaxY;
	  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	     xScroll = document.body.scrollWidth;
	     yScroll = document.body.scrollHeight;
	  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	     xScroll = document.body.offsetWidth;
	     yScroll = document.body.offsetHeight;
	  }
	  var windowWidth, windowHeight;
	  if (self.innerHeight) {   // all except Explorer
	     windowWidth = self.innerWidth;
	     windowHeight = self.innerHeight;
	  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	     windowWidth = document.documentElement.clientWidth;
	     windowHeight = document.documentElement.clientHeight;
	  } else if (document.body) { // other Explorers
	     windowWidth = document.body.clientWidth;
	     windowHeight = document.body.clientHeight;
	  }
	  // for small pages with total height less then height of the viewport
	  if(yScroll < windowHeight){
	     pageHeight = windowHeight;
	  } else {
	     pageHeight = yScroll;
	  }
	  // for small pages with total width less then width of the viewport
	  if(xScroll < windowWidth){
	     pageWidth = windowWidth;
	  } else {
	     pageWidth = xScroll;
	  }
	  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	  return arrayPageSize;
	}


function AutocompleteInit() {
	//alert("ok")
		$("#tSearch").autocompleste("/com/autocomplete.php",
				{
				delay:10,
				minChars:0, 
				matchSubset:1,
				maxItemsToShow: 20,
				matchContains:1,
				cacheLength:-100,
				autoFill:true
				});	
}

function getSubID(li) {
	var sValue = li.extra[0];
	if(sValue) {
	document.getElementById("SubID").value = sValue;
	document.getElementById("tSearch").focus();
	}
	else {
	document.getElementById("SubID").value = 0;
	}
}
function RealLine(){
	var items = $("#RealizationsList div.Item").length;
	//alert(items)
	//alert(4 % 2)
	var wynik = items % 2;
	if(wynik==0) {
	$("#RealizationsList div.Item:last-child").addClass('last');
	$("#RealizationsList div.Item:last-child").prev().addClass('last');
	} else
		$("#RealizationsList div.Item:last-child").addClass('last');
}
