/*
	@created: 8.10.2009 16:42
	@edit: 23.08.2010 9:22
*/

if( typeof jQuery == 'undefined' ){}
else
{
	$(document).ready(function(){
		/* pop-up aken */
		$('a[rel="popup"]').click(function(){
			uus_popup_aken(this.href);
			return false;
		});
	});

	$(window).load(function(){
		/* prettyphoto, lightbox */
		if( $('a[rel^=prettyphoto], a[rel^=lightbox]').length > 0 )
		{
			$('<link>').appendTo('head').attr({
				rel: 'stylesheet', 
				type: 'text/css', 
				href: kodulehe_aadress  + 'kujundused/iitee/assets/css/prettyPhoto.css'
			});

			$.getScript(kodulehe_aadress + 'js/jquery.prettyPhoto.js', function(){
				$("a[rel^=prettyPhoto], a[rel^=lightbox]").prettyPhoto({
					animationSpeed: 'normal', /* fast/slow/normal */
					opacity: 0.35, /* Value between 0 and 1 */
					showTitle: true, /* true/false */
					allowresize: true, /* true/false */
					default_width: 500,
					default_height: 344,
					counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
					theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
					hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
					wmode: 'opaque', /* Set the flash wmode attribute */
					autoplay: false, /* Automatically start videos: True/False */
					modal: false, /* If set to true, only the close button will close the window */
					changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
					callback: function(){}, /* Called when prettyPhoto is closed */
					markup: '<div class="pp_pic_holder"> \
								<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_fade"> \
												<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
												<div class="pp_loaderIcon"></div> \
												<div class="pp_hoverContainer"> \
													<a class="pp_next" href="javascript:void(0);">next</a> \
													<a class="pp_previous" href="javascript:void(0);">previous</a> \
												</div> \
												<div id="pp_full_res"></div> \
												<div class="pp_details clearfix"> \
													<a class="pp_close" href="#">Close</a> \
													<p class="pp_description"></p> \
													<div class="pp_nav"> \
														<a href="javascript:void(0);" class="pp_arrow_previous">Previous</a> \
														<p class="currentTextHolder">0/0</p> \
														<a href="javascript:void(0);" class="pp_arrow_next">Next</a> \
													</div> \
												</div> \
											</div> \
										</div> \
									</div> \
									</div> \
								</div> \
								<div class="pp_bottom"> \
									<div class="pp_left"></div> \
									<div class="pp_middle"></div> \
									<div class="pp_right"></div> \
								</div> \
							</div> \
							<div class="pp_overlay"></div> \
							<div class="ppt"></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>'
				});
			});
		}

		/* teenuste ikoonide vahetused */
		if( $('table.teenuse_rida').length > 0 )
		{
			$('table.teenuse_rida').each(function(i){
				var pic = $(this).find('img'), opic = $(pic).attr('src');

				if( opic.match(/(\_mv.jpg)$/i) )
				{
					$(this).hover(function(){
						var npic = opic.replace(/_mv/gi, '');
						$(pic).attr('src', npic);
					}, function(){
						$(pic).attr('src', opic)
					});
				}
			});
		}
	});

	/*asukoha_kaart(aadress);*/
	function asukoha_kaart(x, y, m_data, icon_image, layer_id)
	{
		$.getScript(kodulehe_aadress + 'js/markerclusterer.js', function(){
			var center = new google.maps.LatLng(x, y);
			var options = {
				zoom: 7,
				center : center,
				mapTypeControl: true,
				mapTypeControlOptions: {
					style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, 
					position: google.maps.ControlPosition.TOP_RIGHT
				},
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};

			var map = new google.maps.Map(document.getElementById(layer_id), options);
			var markers = [];
			//var infoWindow = new google.maps.InfoWindow({});

			if( icon_image == 'none' || !icon_image ){}
			else
			{
				var image = new google.maps.MarkerImage(icon_image, 
				  // This marker is 20 pixels wide by 32 pixels tall. 
				  new google.maps.Size(32, 32), 
				  // The origin for this image is 0,0. 
				  new google.maps.Point(0,0), 
				  // The anchor for this image is the base of the flagpole at 0,32. 
				  new google.maps.Point(0, 32));
			}

			for(var i=0;i<m_data.length;i++)
			{
				var infoWindow = new google.maps.InfoWindow({});

				var bodytxt = ( m_data[i].info == '' ? m_data[i].title : m_data[i].info.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g, '"') );
				var latLng = new google.maps.LatLng(m_data[i].latitude, m_data[i].longitude);

				if( icon_image == 'none' || !icon_image )
				{
					var marker = new google.maps.Marker({
						position:latLng,
						title:m_data[i].title,
						draggable:false
					});
				}
				else
				{
					var marker = new google.maps.Marker({
						position:latLng,
						title:m_data[i].title,
						icon:image,
						draggable:false
					});
				}

				infoWindowHtml = '<div class="gmap_sisu" style="height:' + (bodytxt.length+10) + 'px;">' + bodytxt + '<\/div>';
				infoWindow.setContent(infoWindowHtml);
				infoWindow.open(map, marker);

				markers.push(marker);
			}

			var mc = new MarkerClusterer(map, markers);
		});
	}
}


/*
	Abiunktsioonid
	==============
*/
/*
	uus popup aken
	--------------
*/
function uus_popup_aken(link, laius, korgus)
{
	if(!laius) var laius = 800; // 770
	if(!korgus) var korgus = 600; // 650

	var left = parseInt((screen.availWidth/2) - (laius/2));
	var top = parseInt((screen.availHeight/2) - (korgus/2));

	window.open(link, '_blank', 
		'scrollbars=yes,toolbar=no,location=no,status=no,width=' + laius + ',height=' + korgus 
		+ ',screenX=' + left + ',screenY=' + top);
};

