/*=======================================================================*/
// [[[ Bookmark creation for startpage

function CreateBookmarkLink() {

	title 	= document.title; 
	url 	= location.href;
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

// ]]]  Bookmark creation for startpage
/*=======================================================================*/
// [[[ Actions that are connected to big header baner, its moving, closing, image rotating

	$(document).ready( function(){ 
		
		$barStatus = readCookie('headerImageStatus');//reading open/close image bar cookie
		if ($barStatus != 'closed') {
			//zapuskaem rotating imagei
			$('#fade').innerfade({ 
				speed: 'slow', 
				timeout: 4000, 
				type: 'sequence', 
				containerheight: '230px'
			});
			window.$started = 1;
		} else {
			hideBlock(0);
		}
		
		
		$('#hideUnhideTopImage').click(function(){//ustanavlivaem event na otkritie zakritie top imag rotatora
				
			if ($('#fadeImgButtons').is(':hidden')) {
				showBlock();
				createCookie('headerImageStatus','opened', 5);
			} else {
				hideBlock(400);
		        createCookie('headerImageStatus','closed', 5);//was stoit 5 minut kak test
			}
		});
		
	}); 

	function showBlock(){
		
		//ustanavlivaem image sliding effect, pokazivaem imag + strelki, menjajem image (open) na close
		cssObj = {
			'text-align' 	 : 'right',
			'height' 		 : '153px',
			'display' 		 : '',
			'border'		 : '0px solid red',
			'width'	 		 : '940px',
			'clear'			 : 'both',
			'padding'		 : '0px',
			'margin'		 : '0px'
		};
		
		$('#hideUnhideTopImage').parent().css('height', '80px');
		$('#hideUnhideTopImage img:first-child').attr("src", "images/building/minimize.png");
		$('#fadeImgButtons').show(400, function(){ 
			$('#fadeImgButtons').css(cssObj);
			if ($.browser.mozilla){
				$('#prevFade').css({"margin-left":"-44px"});
				//$('#hideUnhideTopImage').parent().css({'text-align':'right','display':''});
				//$('#hideUnhideTopImage').css({'display':'inline','text-align':'right'});
				$('#hideUnhideTopImage img').css({'position':'relative', 'left':'877px'});
				$('#hideUnhideTopImage img').parent().css({'position':'relative', 'left' : '0px'});//added
			}
			$('#hideUnhideTopImage img').css({'margin-top':'-22px'});
		});
		
        $('#fade').show(400);
        $childs = $('#fade').children().length;
        if ($childs != 1) {
			$('#fade').innerfade({ 
				speed: 'slow', 
				timeout: 4000, 
				type: 'sequence', 
				containerheight: '230px'
			});	
        } else {
        	 $childs = $('#fade li').show();
        }
	}
	
	var $firstShowed;
	
	function hideBlock($speed){
		
		//snimaem image sliding effect i hiddenim curent opened image, menjajem image (close) na open
		window.clearTimeout(window.$fadeTimeout);
		window.$fadeTimeout = null;
		
		elements = $('#fade').children();
	 	for (var i = 0; i < elements.length; i++) {
            $(elements[i]).hide();
        };
        $('#hideUnhideTopImage').parent().css('height', '4px');
        $('#hideUnhideTopImage img').attr("src", "images/building/maximize.png");
        //$('#hideUnhideTopImage img:first-child').css({'position':'static', 'left':'0px'});
        $('#hideUnhideTopImage img').css({'position':'relative', 'right':'45px', 'margin-top':'-11px', 'z-index':'100'});//added
        if ($.browser.mozilla){
        	if ($firstShowed) {
        		$('#hideUnhideTopImage img').css({'left':'0px'});//added
        		$('#hideUnhideTopImage img').parent().css({'left':'1047px','display':'block'});//added
        	}
        	$firstShowed = 1;
        }
        $('#hideUnhideTopImage img').parent().css({'position':'absolute'});//added
        $('#fadeImgButtons').hide($speed);
        $('#fade').hide($speed);
	}

// ]]] Actions that are connected to big header baner, its moving, closing, image rotating
/*=======================================================================*/
// [[[ Cookies manipulation

	function createCookie(name, value, $hours) {
		if ($hours) {
			var date = new Date();
			date.setTime(date.getTime()+($hours*60*1000));//*60 u nas was minuti vmesto hours
			var expires = "; expires="+date.toGMTString();
		}else {
			var expires = "";
		}
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

// ]]] Cookies manipulation
/*=======================================================================*/
// [[[ Submiting buttons

	function submitSearch(){
		
		$value = $.trim($("#searchField").attr('value'));
		if ($value.length <3 ) {
			alert("Mēklēšanas vārdam jābūt 3 vai vairāk simboliem");
			return false;
		}
		document.forms['wizard_form'].submit();
		return false;
	}	
	
	function submitF(){
		$fButton = document.getElementById("wizard_form2")
		$fButton.submit();
	}
	
	function checkCommentField(){
		$value = $.trim($("#comentField").val());
		if ($value.length >2000 ) {
			alert("Komentārs nevar būt lielāks par 2000 simboliem");
			$("#comentField").attr('value', $value.substr(0,$value.length-1));
		}
	}

// ]]] Submiting buttons
/*=======================================================================*/
