/*=======================================================================*/
// [[[ 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
/*=======================================================================*/
// [[[ Links opening in other window

	function externallinks(){
	    var c=document;
	    if(c){
	        var ls=c.getElementsByTagName('a');
	        for(var i=0; i<ls.length; i++){
	        	
				if(ls[i].getAttribute('target')) {
					if (ls[i].getAttribute('target') == '_blank') {
						ls[i].setAttribute('rel','external');
					}
					ls[i].removeAttribute('target');
				}
	            if(ls[i].getAttribute('rel')=='external'){
	                ls[i].className+=ls[i].className?' extlink':'extlink';
	                ls[i].title+='(opens in new window)';
	                ls[i].onclick=function(){window.open(this.href);return false}
	            }
	        }
	    }
	}


// ]]] Links opening in other window
/*=======================================================================*/
// [[[ Actions that are connected to big header baner, its moving, closing, image rotating

	$(document).ready( function(){ 
		
		var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
		var ie6  = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		if ($.browser.msie && (ie55 || ie6)) {
			$(document).pngFix();
		}
		 externallinks();
//		 $('.link').click(function(){
//			OpenCloseProject(this);
//			return false;
//		 });

		 $("a.simpleImage").fancybox({
		 	'hideOnContentClick': true
		 });
		 $("a.group").fancybox({
		 	'zoomSpeedIn' : 300, 
		 	'zoomSpeedOut': 300,
		 	'easingIn'	  : 'easeOutBack',
			'easingOut'	  : 'easeInBack'
		 }); 
		 $("#openPopup").trigger('click');
	}); 
	
	function changeImg($obj, $src){
		$obj.src = $src;
	}
	function changeImg2($id, $src){
		//alert(document.getElementById($id).src);
		document.getElementById($id).src = $src;
	}
	
/*=======================================================================*/
// [[[ KARUSELJ

	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){
	    // The index() method calculates the index from a
	    // given index who is out of the actual item range.
	    var idx = carousel.index(i, mycarousel_itemList.length);
	    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	};
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){
	    carousel.remove(i);
	};
	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item){
	    return '<img src="' + item.url + '" width="110" height="84" alt="' + item.desc + '" />';
	};

	function mycarousel_initCallback(carousel){
	    // Disable autoscrolling if the user clicks the prev or next button.
	    carousel.buttonNext.bind('click', function() {
	        carousel.startAuto(0);
	    });
	
	    carousel.buttonPrev.bind('click', function() {
	        carousel.startAuto(0);
	    });
	
	    // Pause autoscrolling if the user moves with the cursor over the clip.
	    carousel.clip.hover(function() {
	        carousel.stopAuto();
	    }, function() {
	        carousel.startAuto();
	    });
	};

// ]]] KARUSELJ
/*=======================================================================*/
// [[[ 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 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
/*=======================================================================*/
// [[[ Opening/ Closing

	function OpenCloseProject($obj){
		
		$uls 	= $($obj).parent().find('ul');
		$status = $($obj).attr('status');
		if (!$uls.length) return;
		
		$($obj).toggleClass("act");
		if (!$status) $status = 'closed';
		if ($status == 'closed') {
			//opening hidden ul list
			$uls.show('normal');
			$newStatus = 'opened';
		} else {
			//closing
			$uls.hide('normal');
			$newStatus = 'closed';
		}
		$($obj).attr('status', $newStatus);
	}
	
	var $timeout;
	
	function showHideSertificate($sertImg, e){
		
		if (!e) e = window.event;
		
		$status = $('#sertificate').attr('status');
		if ($status == 'opened') {
			$timeout = setTimeout('hideSertificate()', 700);
		} else {
			if ($timeout) {
				clearTimeout($timeout);
			}
			eleOffset = $('#sertificate').position();
			$('#sertificate').css({
				'left' 	 : e.clientX+20,
				'top' 	 : e.clientY-80
				//'display': 'block'
			});
			$('#sertificate').show(400);
			$('#sertificate').attr('status', 'opened');
			$('#sertificate img:last').attr('src', "images/building/"+$sertImg);
		}
	}
	
	function hideSertificate(){
		$('#sertificate').css('display','none');
		$('#sertificate').attr('status', 'hidden');
	}

// ]]] Opening/ Closing
/*=======================================================================*/
