var lists=[];
var lists2=[];
var lists_ids=[];
var lists2_ids=[];

$(document).ready(function() {
	if($('#Ind').length){
		$('input[name=Ind]').val('0');
	}
	$('#blog_li_wrapper').height(428);
	$('#blog_slider').anythingSlider({
	  width:319,
	  height:$('#blog_li_wrapper').height(),
	  startPanel: 1,
	  autoPlay: false,
	  startStopped: true,
	  animationTime: 1000,
	  hashTags: true,
	  buildArrows: false,
	  delay: 1000,
	  buildNavigation: true,
	  navigationFormatter: null,
	  pauseOnHover: true,
	  startText: "",
	  stopText: ""
	});	
        	


	if($('#sirens_left').length && window.location.hash){
		var prefix = window.location.hash.substr(1,1);
		var id = window.location.hash.substring(2,window.location.hash.length );
		if(prefix =='g'){
			$.ajax({
				type: "POST",
				url: "/index.php/en/sirens/",
				data: "hash="+id,
				success: function(msg){			
					show_gallery(msg,id,1);
				}	
			});
		}
		else{
			$.ajax({
				type: "POST",
				url: "/index.php/en/sirens/",
				data: "open_story="+id,
				dataType: "json",
				success: function(msg){	
					if(msg.id==0){
						id=2981;
						window.location.hash ='s' + id;					
						story(msg.story,msg.title,0);						
					}else{
						window.location.hash ='s' + id;					
						story(msg.story,msg.title,msg.last);						
					}		

				}	
			});			
		}
	}
	
	var Backgrounds = ['books','progress','media','cfr','biography', 'sirens'];	
	 jQuery.each(Backgrounds, function() {
		if($('#'+this+'_back').height()<$(window).height()-115){	
			$('#'+this+'_back').height($(window).height()-110);
		}
	 });
	
	 if($('#hidden_back').length){
	 	$('#hidden_right').height($(document).height()-120);
	 }
	 
/*
	 var Backgrounds = ['home','sirens','books','progress','media','cfr','biography', 'sirens','blog'];	
	
	 jQuery.each(Backgrounds, function() {
	 		if($('#'+this+'_back').length){
				if($('#'+this+'_left').height()>$('#'+this+'_right').height()){
					$('#'+this+'_right').height($('#'+this+'_left').height());
				}
			}
	 });
*/
	
	var Sections = ['biography', 'sirens', 'books', 'cfr', 'media','progress'];
	
	for (var i in Sections)
	{
		if (!$('#' + Sections[i] + '_left').length)
		{
			continue;
		}
		if(Sections[i]=='sirens'){
			var Images = $('#' + Sections[i] + '_left').find('div:not(:empty)').map(function() { return this.id ? this.id : null; }).get();
		}else{
			var Images = $('#' + Sections[i] + '_left').find('div:not(:empty)').map(function() { return this.id ? this.id : null; }).get();
		}		

		if ($('#' + Sections[i] + '_marker').val() != '0')
		{
			if(Sections[i]=='progress'){
				$('#' + Sections[i] + '_left div img').show().css('top', 0).css('left', 0);
			}else{
				$('#' + Sections[i] + '_left div div').show().css('top', 4).css('left', 4);
			}
			
		}
		else
		{
			var ImageCtr = 0, ID;

			function SlideDelay()
			{
				ID = Images[ImageCtr++];
				if (ID)
				{
//					$('#'+ID+' div, #'+ID+'_active div').animate({top: '4px', left: '4px'}, 400, 'swing', SlideDelay);
					if($('#progress_left').length){
						$('#'+ID+' img, #'+ID+'_active img').fadeIn(400,SlideDelay);
					}else{
						$('#'+ID+' div, #'+ID+'_active div').fadeIn(400,SlideDelay);
					}
				}
			}

			setTimeout(SlideDelay, 1000);
		}
	}
	
/*
	if($('#progress_marker').length){	
		if($('#progress_marker').val()=='0'){	
			$('.dynamic img').each(function(){
				$(this).fadeIn(2000);
			});
		}
		else{
			$('.dynamic img').each(function(){
				$(this).fadeIn(0);
			});
		}
	}
*/
	
	
	$(window).scroll(function() {		
	var Backgrounds = ['home','books','progress','media','cfr','biography','blog'];	
	var Heights = [526,552,0,476,455,476,496];		
	
	jQuery.each(Backgrounds, function(i) {
		 if($('#'+this+'_left').length > 0){
			$('#'+this+'_left').offset();

				var windowOffset = $(window).scrollTop();
				if(this=='progress'){
					var pageHeight = 70 + 50 + $('#progress_left').height() + 15; // top + menu + books_left + books_left top margin
				}else{
					var pageHeight = 70 + 50 + Heights[i] + 15; // top + menu + books_left + books_left top margin
				}
				var windowHeight = $(window).height();
				var altOffset =  windowOffset;
	
				if(windowHeight < pageHeight){
				   if(pageHeight - windowHeight > altOffset){
				    $('#'+this+'_left').addClass(this+'_left_relative');

				    $('#'+this+'_left').removeClass(this+'_left_fixed_top');
				    $('#'+this+'_left').removeClass(this+'_left_fixed_bottom');
				   }else{
				    $('#'+this+'_left').removeClass(this+'_left_relative');
				    $('#'+this+'_left').removeClass(this+'_left_fixed_top');
				    $('#'+this+'_left').addClass(this+'_left_fixed_bottom');
				   }
				  }
		} 		 	
	 });
	});

	
	if($('#sirens_back').length > 0){
	$('#sirens_left').offset();
	
	 $('#sirens_back').css('background-position',$("#sirens_left").offset().left+'px top');

		$(window).scroll(function() {
		
		
			var galleryHeight = $('#gallery').height();
			var uploadHeight = $('#upload').height();
			var storyheight = $('#Story_gallery').height();			
			var windowOffset = $(window).scrollTop();
			var pageHeight = 120 + 552 + 11; // top + menu + sirens_left + sirens_left top margin
			var windowHeight = $(window).height();
			var altOffset = 0;
			
			if($('#gallery').height() > 0){
				if(windowOffset > galleryHeight){
					$('#sirens_left').addClass('sirens_left_fixed_top');
					$('#sirens_left').removeClass('sirens_left_relative');									
					$('#top').css({'position': 'fixed', 'top': '0px'});
					$('#menu').css({'position': 'fixed', 'top': '70px'});	
				}else{
					$('#sirens_left').removeClass('sirens_left_fixed_top');
					$('#sirens_left').removeClass('sirens_left_fixed_bottom');
					$('#sirens_left').addClass('sirens_left_relative');
					$('#top').css({'position': 'relative', 'top': '0px','left':'0'});
					$('#menu').css({'position': 'relative', 'top': '0px','left':'0'});					
				}						
			}
			
			
			
			if($('#upload').height() > 0){
				if(windowOffset > uploadHeight){
					$('#sirens_left').removeClass('sirens_left_relative');									
					$('#sirens_left').addClass('sirens_left_fixed_top');
					$('#top').css({'position': 'fixed', 'top': '0px'});
					$('#menu').css({'position': 'fixed', 'top': '70px'});	
				}else{
					$('#sirens_left').removeClass('sirens_left_fixed_top');
					$('#sirens_left').removeClass('sirens_left_fixed_bottom');
					$('#sirens_left').addClass('sirens_left_relative');
					$('#top').css({'position': 'relative', 'top': '0px','left':'0'});
					$('#menu').css({'position': 'relative', 'top': '0px','left':'0'});
				}			
			
			}
			
			if($('#gallery').height() > 0){
				altOffset = windowOffset - galleryHeight;
			}else if ($('#upload').height() > 0){
				altOffset = windowOffset - uploadHeight;
			}else{
				altOffset = windowOffset;
			}

									
			
			if(windowHeight < pageHeight){					
				if($('html').scrollTop()==$('body').height()+20){	
				    $('#sirens_left').removeClass('sirens_left_relative');
				    $('#sirens_left').removeClass('sirens_left_fixed_top');
				    $('#sirens_left').addClass('sirens_left_fixed_bottom');				
				    $('#sirens_left').removeAttr("style");
				}
			  	else if(pageHeight - windowHeight > altOffset){
			    $('#sirens_left').removeClass('sirens_left_fixed_top');
			    $('#sirens_left').removeClass('sirens_left_fixed_bottom');    
			    $('#sirens_left').addClass('sirens_left_relative');
			   }else{
			    $('#sirens_left').removeClass('sirens_left_relative');
			    $('#sirens_left').removeClass('sirens_left_fixed_top');
			    $('#sirens_left').addClass('sirens_left_fixed_bottom');
			   }
			  }
				
		});
		
	} 
	
	
		
	
	var aca123 =0;
	var masivs = ['#biography_right','#cfr_right','#progress_right','#books_right','#sirens_right'];
	
	$.each(masivs,function(a,b){
		$(b).find('img').each(function(){
			if(aca123%2==0){
				$(this).css('float','left');
				$(this).addClass('img_left');
			}else{
				$(this).css('float','right');
				$(this).addClass('img_right');
			}
			aca123=aca123+1;
		});
	});	
	
	$('#slide1').cycle({
 		fx:'fade', 
	    pager:  '#nav1',
	    pause:1,  		
    	timeout: 5000
	});
	$('#slide2').cycle({
		fx:'fade', 
	    pager:  '#nav2', 
	    pause:1,	    		
    	timeout: 7000
	});
	 $('#slide3').cycle({
		fx:'fade',
	    pause:1,		
	    pager:  '#nav3', 		 
    	timeout: 9000
	});	
	$('#Send').bind('click', function() {
		check_fields();
	});	
	$('#Send2').bind('click', function() {
		check_fields_review();
	});	
	$('#Send3').bind('click', function() {
		check_fields_comment();
	});		
	$('#Name').val('your name');
	$('#Name2').val('your name');	
	$('#Name3').val('your name');		
	$('#Mail').val('your e-mail address');
	$('#Mail2').val('your e-mail address');	
	$('#upload_name').val('your name');	
	$('#upload_mail').val('your e-mail');		
	$('#upload_title').val('title');	
	$('#upload_text').val('your 9/11 story');			
	$('#Message').val('your message');
	$('#Comment3').val('your comment');	
	$('#Message2').val('your review');	
	$('#Website2').val('your website (optional)');		
	$('#Webpage3').val('your webpage address (optional)');			
	$('#questions a').css('color','#ff0014');
	$('#bookings a').css('color','#fff');
	$('#Ind').val('0');	
	
	
						
	$('#Name3').focus(function() {
		if($('#Name3').val()=='your name'){
			$('#Name3').val('');
		}
	});

	$('#Name3').blur(function() {
			if($('#Name3').val().length==0){
			$('#Name3').val('your name');
		}

	});	
	
	$('#Comment3').focus(function() {
		if($('#Comment3').val()=='your comment'){
			$('#Comment3').val('');
		}
	});

	$('#Comment3').blur(function() {
			if($('#Comment3').val().length==0){
			$('#Comment3').val('your comment');
		}

	});
						
	$('#Webpage3').focus(function() {
		if($('#Webpage3').val()=='your webpage address (optional)'){
			$('#Webpage3').val('');
		}
	});

	$('#Webpage3').blur(function() {
			if($('#Webpage3').val().length==0){
			$('#Webpage3').val('your webpage address (optional)');
		}

	});
	
	
	
					
	$('#Name2').focus(function() {
		if($('#Name2').val()=='your name'){
			$('#Name2').val('');
		}
	});

	$('#Name2').blur(function() {
			if($('#Name2').val().length==0){
			$('#Name2').val('your name');
		}

	});
	
	
	$('#Website2').focus(function() {
		if($('#Website2').val()=='your website (optional)'){
			$('#Website2').val('');
		}
	});

	$('#Website2').blur(function() {
			if($('#Website2').val().length==0){
			$('#Website2').val('your website (optional)');
		}

	});

	$('#Mail2').focus(function() {
		if($('#Mail2').val()=='your e-mail address'){
			$('#Mail2').val('');
		}
	});
	$('#Mail2').blur(function() {
		if($('#Mail2').val().length==0){
			$('#Mail2').val('your e-mail address');
		}
	});
	$('#Message2').focus(function() {
		if($('#Message2').val()=='your review'){
			$('#Message2').val('');
		}
	});
		$('#Message2').blur(function() {
		if($('#Message2').val().length==0){
			$('#Message2').val('your review');			
		}
	});

	
	
	
	
				
	$('#Name').focus(function() {
		if($('#Name').val()=='your name'){
			$('#Name').val('');
		}
	});

	$('#Name').blur(function() {
			if($('#Name').val().length==0){
			$('#Name').val('your name');
		}

	});

	$('#Mail').focus(function() {
		if($('#Mail').val()=='your e-mail address'){
			$('#Mail').val('');
		}
	});
	$('#Mail').blur(function() {
		if($('#Mail').val().length==0){
			$('#Mail').val('your e-mail address');
		}
	});
	$('#Message').focus(function() {
		if($('#Message').val()=='your message'){
			$('#Message').val('');
		}
	});
		$('#Message').blur(function() {
		if($('#Message').val().length==0){
			$('#Message').val('your message');			
		}
	});

	$('#nav1 a').bind('click', function() {
		$('#slide1').cycle('pause');
	});	
	$('#nav2 a').bind('click', function() {
		$('#slide2').cycle('pause');
	});	

	$('#nav3 a').bind('click', function() {
		$('#slide3').cycle('pause');
	});	
	$('#nav1').css('width',	($('#nav1').children().length)*23);
	$('#nav1').css('left', (592-($('#nav1').children().length)*23)/2+5);

	if ($('#nav2 a').length > 15)
	{
		$('#nav2 a').css('width', '18px');
		$('#nav2').css('width',	($('#nav2').children().length)*18);
		$('#nav2').css('left', (297-($('#nav2').children().length)*18)/2+5);
	}
	else
	{
		$('#nav2 a').css('width', '20px');
		$('#nav2').css('width',	($('#nav2').children().length)*20);
		$('#nav2').css('left', (297-($('#nav2').children().length)*20)/2+5);
	}

	if ($('#nav3 a').length > 15)
	{
		$('#nav3 a').css('width', '18px');
		$('#nav3').css('width',	($('#nav3').children().length)*20);
		$('#nav3').css('left', (297-($('#nav3').children().length)*20)/2+303);
	}
	else
	{
		$('#nav3 a').css('width', '20px');
		$('#nav3').css('width',	($('#nav3').children().length)*20);
		$('#nav3').css('left', (297-($('#nav3').children().length)*20)/2+303);
	}

	var listItems = $("#Nav a");
	listItems.each(function(idx, li) {
		$(this).css('width',$(this).width()+20);
	});
	

});

function myJsFunc(){
	$('#questions a').css('color','#ff0014');
	$('#bookings a').css('color','#fff');
	$('input[name=Ind]').val('0');
}
function myJsFunc2(){
	$('#questions a').css('color','#fff');
	$('#bookings a').css('color','#ff0014');	
	$('input[name=Ind]').val('1');	
}
function check_fields_comment(){
	name = msg = false;
	if($('#Name3').val().length!=0 && $('#Name3').val()!='your name'){
		var name= true;
	}else{
		var name= false;
	}
	if($('#Comment3').val().length!=0 && $('#Comment3').val()!='your comment'){
		var msg= true;
	}else{
		var msg= false;
	}		
	if(name && msg){
		$('#CommentForm').submit();
	}
	else{
		if(!name){
			$('#Name3').css('border-color','red');		
		}else{
			$('#Name3').css('border-color','#8F8F8F');	
		}
		if(!msg){
			$('#Comment3').css('border-color','red');	
		}else{
			$('#Comment3').css('border-color','#8F8F8F');	
		}
	}
}
function check_fields_review(){
	name = mail = msg = false;
	if($('#Name2').val().length!=0 && $('#Name2').val()!='your name'){
		var name= true;
	}else{
		var name= false;
	}
	if(isValidEmailAddress( $('#Mail2').val() ) && $('#Mail2').val()!='your e-mail address'){
		var mail= true;
	}else{
		var mail= false;
	}
	if($('#Message2').val().length!=0 && $('#Message2').val()!='your review'){
		var msg= true;
	}else{
		var msg= false;
	}		
	if(name && mail && msg){
		$('#ReviewForm').submit();
	}
	else{
		if(!name){
			$('#Name2').css('border-color','red');		
		}else{
			$('#Name2').css('border-color','#8F8F8F');	
		}
		if(!mail){
			$('#Mail2').css('border-color','red');	
		}else{
			$('#Mail2').css('border-color','#8F8F8F');	
		}
		if(!msg){
			$('#Message2').css('border-color','red');	
		}else{
			$('#Message2').css('border-color','#8F8F8F');	
		}
	}
}
function check_fields(){
	name = mail = msg = false;
	if($('#Name').val().length!=0 && $('#Name').val()!='your name'){
		var name= true;
	}else{
		var name= false;
	}
	if(isValidEmailAddress( $('#Mail').val() ) && $('#Mail').val()!='your e-mail address'){
		var mail= true;
	}else{
		var mail= false;
	}
	if($('#Message').val().length!=0 && $('#Message').val()!='your message'){
		var msg= true;
	}else{
		var msg= false;
	}		
	if(name && mail && msg){
		$('#ContactForm').submit();
	}
	else{
		if(!name){
			$('#Name').css('border-color','red');		
		}else{
			$('#Name').css('border-color','#8F8F8F');	
		}
		if(!mail){
			$('#Mail').css('border-color','red');	
		}else{
			$('#Mail').css('border-color','#8F8F8F');	
		}
		if(!msg){
			$('#Message').css('border-color','red');	
		}else{
			$('#Message').css('border-color','#8F8F8F');	
		}
	}
}
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
};

function limit(){
}
function story(story,title,last){
/* 	if(!$('#share_your_story').length){ */
/* 		$('#share_your_story').show(); */
/* 	} */
	var prefix = window.location.hash.substr(1,1);
	var id = window.location.hash.substring(2,window.location.hash.length );

	if(!window.location.hash || prefix=='g'){
		window.location.hash='s'+2981;
	}
	//$('#sirens_left').css({'position': 'relative', 'top': '0px'});
	$('#top').css({'position': 'relative', 'top': '0px','left':'0'});
	$('#menu').css({'position': 'relative', 'top': '0px','left':'0'});				
	$('#sirens_left').addClass('sirens_left_relative');

	if(!$.browser.webkit){
		$('#sirens_right').css('margin-top','-2px');						
//		$('#sirens_left').css('top','4px');					
		$('#sirens_left').css('margin-left','0px');					
	}
	
	if($('#gallery')){
		$('#gallery').hide();
		$('#gallery').height(0);			
	}
/*
	if($('#upload').css("display") == 'none' || $('#Story_gallery').css("display") == 'none'){
		$('#upload').html('');
		$('#upload').css('height',0);		
	}
*/
	if($('#upload').height()>100 || $('#Story_gallery').height()>100){		
		if($.browser.webkit){
			var Scrollable = "body";
		}else{
			var Scrollable = "html";
		}
		$(Scrollable).animate({ scrollTop: 0 }, "slow",function(){
			if(!$('#opened_imgg2').length){
				$('#Story_gallery_closer').show();
				$('#Story_gallery').css('height','0px');
				$('#Story_gallery').show();
			}
		});
	}else{		
		$('#upload').html('');
		$('#upload').css('height',0);		
		$('#Story_gallery').html('');
		$('#Story_gallery').css('height',0);			
		 var viewportheight;
		 if (typeof window.innerWidth != 'undefined')
		 {
		      viewportheight = window.innerHeight
		 }
		 else if (typeof document.documentElement != 'undefined'
		     && typeof document.documentElement.clientWidth !=
		     'undefined' && document.documentElement.clientWidth != 0)
		 {
		       viewportheight = document.documentElement.clientHeight
		 } 
		 else
		 {
		       viewportheight = document.getElementsByTagName('body')[0].clientHeight
		 }
		var upload_h= viewportheight-114;
		if(upload_h<=500){
			upload_h=500;
		}	
	
		$.ajax({
			type: "POST",
			url: "/index.php/en/sirens/",
			data: "upload=1",	
			dataType: "json",	
			success: function(msg){
				$('#upload').html(msg.story);
				$('#upload_left').css('height',upload_h);		
				$('#upload_right').css('height',upload_h);				
				if(title){
					$('#story_over').html(story);	
					$('#story_title').html(title);						
				}
			$('#Story_gallery').hide();			
			$('#share_your_story').hide();			
			$('#wpload_holder').show();						
			$('#Story_gallery').css('z-index','0');									
			$('#Story_gallery_closer2').show();
			

		$('#upload').animate({height : upload_h+'px' },function(){		
		if($.browser.webkit){
			var Scrollable = "body";
		}else{
			var Scrollable = "html";
		}
		$(Scrollable).animate({ scrollTop: 0 }, "slow",function(){
			var uploader = new qq.FileUploader({
	            element: document.getElementById('file-uploader'),
				action: '/upload2.php',		
				multiple: false,	
				allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],       
				onProgress: function(id, fileName, loaded, total){
								$('.qq-upload-button').hide();
				},				 
				onComplete: function(id, fileName, responseJSON){
				if(responseJSON.success){
					$('#file-uploader').html('Image uploaded.');						
					$('#title').val(responseJSON.success);												
				}else{
					$('.qq-upload-button').show();
					$('#title').val(responseJSON.error);	
				}
				
				},
				debug: false
			});
			$('#Story_gallery').height($('#upload').height()-37);		
			$('#story_over').jScrollPane({showArrows: true});		
					if($('.jspArrowDown').length){
							$('#scroll_splitter').show();							
						}else{
							$('#scroll_splitter').hide();
						}
		
		});
				if($('#story_augstumam div').height()<331){
					$('#storie_controls2').hide();				
				}else{
					$('#storie_controls2').show();				
				}
				if(window.location.hash=='#s2981'){
					$('#story_galery_prev').hide();
					$('#storie_splitter1').hide();		
					$('#story_galery_next').hide();
					$('#story_galery_next2').show();					
				}else{
					$('#story_galery_prev').show();
					$('#storie_splitter1').show();										
					$('#story_galery_next').show();
					$('#story_galery_next2').hide();
				}
				if(last==1){
					$('#story_galery_prev').show();
					$('#storie_splitter1').hide();										
					$('#story_galery_next').hide();
					$('#story_galery_next2').hide();
				}

		
});	

}
});
	}
		
}
function show_gallery(name,id,hash){


	if($('#share_your_story').length){
		$('#share_your_story').hide();
	}
	//$('#sirens_left').css({'position': 'relative', 'top': '0px'});

	if(!$.browser.webkit){
		$('#sirens_right').css('margin-top','-2px');					
//		$('#sirens_left').css('top','4px');							
	}
	if($('#upload')){
		$('#upload').hide();
		$('#upload').css('height','0px');		
	}
	if($('#gallery').height()!=0){
		if($.browser.webkit){
			var Scrollable = "body";
		}else{
			var Scrollable = "html";
		}
		$(Scrollable).animate({ scrollTop: 0 }, "slow");
	}else{		
		 var viewportheight;
		 if (typeof window.innerWidth != 'undefined')
		 {
		      viewportheight = window.innerHeight
		 }
		 else if (typeof document.documentElement != 'undefined'
		     && typeof document.documentElement.clientWidth !=
		     'undefined' && document.documentElement.clientWidth != 0)
		 {
		       viewportheight = document.documentElement.clientHeight
		 } 
		 else
		 {
		       viewportheight = document.getElementsByTagName('body')[0].clientHeight
		 }
		var gal_h= viewportheight-114;
		if(gal_h<=320){
			gal_h=330;
		}
		var gal_h2= gal_h-37;
		 	var platums  = $(window).width();
			$.ajax({
			type: "POST",
			dataType: "json",
			url: "/index.php/en/sirens/",
			data: "platums="+platums+"&augstums="+gal_h2,
			success: function(msg){
						$('#gallery').html(msg.msg);
						var maxW= Math.floor(platums/330);
						var maxH= Math.floor(gal_h2/310);
						if(maxH<=1){
							if($('#gallery').height()>350){
								highh=gal_h-50;
							}else{
								highh=gal_h-22;						
							}
						}else{
								highh=gal_h-70;
						}
						$('#gallery_ul').anythingSlider({
							  width:maxW*330,
							  height:$(window).height()-154,
							  startPanel: 1,
							  autoPlay: false,
							  startStopped: true,
							  animationTime: 1000,
							  hashTags: false,
							  buildArrows: false,
							  delay: 1000,
							  buildNavigation: true,
							  navigationFormatter: null,
							  pauseOnHover: true,
							  startText: "",
							  stopText: ""
							});	
						 jQuery.each(msg.pics, function (i, app) {
				                lists[i+1] = app;
				        });
						 jQuery.each(msg.ids, function (i, app) {
				                lists_ids[i+1] = app;
				        });				        
				        if($('#gallery .thumbNav')){				       
							$('#gallery .thumbNav').css('width',($('#gallery .thumbNav').children().length)*15);			
						}
						if(gal_h<=330){
							$('.anythingSlider').css('padding-top',0);
						}else{
							if(maxH <=1 ){
								$('.anythingSlider').css('padding-top',0);
							}else{
								$('.anythingSlider').css('padding-top',gal_h2-(maxH*310));
							}
						
						}		
					
/*
						var Counter= 0;
						$('#gallery_ul li').each(function(index) {
						 	var curr_element_count = $(this).find('.gal_divs').size();
							if(curr_element_count <=maxW){
								$('#gallery_ul li .gal_divs').each(function(index) {
									var gh= $(window).height()-114;
									if(gh>390){
										$(this).css('padding-top',gh-390);
									}									
								});	
								if(Counter!=0){
									$(this).find('#gal_divs').css('margin-left',($('#gallery').width()-(curr_element_count*330))/2);
								}						
								Counter++;								
							
							}
						});
*/
					$('#sirens_left').addClass('sirens_left_relative');
				$('#top').css({'position': 'relative', 'top': '0px','left':'0'});
				$('#menu').css({'position': 'relative', 'top': '0px','left':'0'});				
		  		$('#gallery').animate({height : gal_h+'px' },"slow",function(){
					if(hash==1){
		
						show_single_img(name,id);
					}
					if($.browser.webkit){
						var Scrollable = "body";
					}else{
						var Scrollable = "html";
					}
					$(Scrollable).animate({ scrollTop: 0 });
					if(!window.location.hash ){
						show_single_img(lists[1],lists_ids[1]);
					}else{
						var prefix = window.location.hash.substr(1,1);
						if(prefix=='s'){
							show_single_img(lists[1],lists_ids[1]);
						}
					}
				});


			}
			
		});
	}
}
function show_single_img(name,id){
	$('#opened_imgg').html('');
	$('#opened_desc').html('');	
	$('#opened_img').css('height',$('#gallery').height());
	$('#opened_img').css('width',$('#gallery').width());		
	$('#opened_img').show();
	window.location.hash='g'+id;
	
	$.ajax({
	type: "POST",
	dataType: "json",	
	url: "/index.php/en/sirens/",
	data: "image="+name+"&pl="+$(window).width()+"&id="+id,
	success: function(msg){			
			$('#gal_photos_nr').html(msg.pos);
			var Width = 950;
			var Height = $('#gallery').height()-120;
			var BySmallestSide = false;
			if (Width){
				var TargetWidth = Width;
				if (Height){
					TargetHeight = Height;
				}else{
					TargetHeight = floor((TargetWidth / msg.width) * msg.height);
				}
			}else if (Height){
				TargetHeight = Height;
				TargetWidth = Math.floor((TargetHeight / msg.height) * msg.width);
			}
			if (Width && Height){
				if ((msg.width / msg.height) > (TargetWidth / TargetHeight)){	
					TargetHeight = Math.floor((TargetWidth / msg.width) * msg.height);
				}else{
					TargetWidth = Math.floor((TargetHeight / msg.height) * msg.width);
				}
			}	
			$('#opened_img').show('fast', function() {
			
				var description = $('#description_'+id).html();
				$('#opened_desc').html(description.substr(0,190)+'...');		 	
/* 				$('#opened_desc p:last-child').append('<span onclick="show_more_text();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'); */
				  
				if(name.substring(0,1)=='"'){
					name = name.substring(1,name.length-1);		
				}
				$('#opened_imgg').html('');
				$('#opened_imgg').html('<img src="/UserFiles/Full/'+ name +'" width="'+ TargetWidth +'" height = "'+TargetHeight+'"/><div style="display:none;" id="curr_id">'+id+'</div>');	
				
				var total= lists_ids.length;
				if(!$('#curr_id').html()){
					var IdToLookFor  = id;			
				}else{
					var IdToLookFor= $('#curr_id').html();
				}
				var pos = jQuery.inArray(IdToLookFor, lists_ids);
				if(pos==total-1){
					$('#gal_next').hide();
				}else{
					if($('#gal_next').css("display") == 'none'){
						$('#gal_next').show();
					}
				}				
				if(pos==1){
					$('#gal_prev').hide();
				}else{
					if($('#gal_prev').css("display") == 'none'){
						$('#gal_prev').show();
					}
				}				 
  			});
			
			if(!$('#opened_img').length){
				show_single_img(name,id);
			}		
			
			if($('#show_texts').html()==0){			
				$('#show_texts').html(0);	
				var description = $('#description_'+id).html();
				$('#opened_desc').css('height', $('#description_'+id).height()+'px');			
				$('#opened_desc').html( description.substr(0,2000));		 
				$('#opened_desc p:last-child').append('<span onclick="show_more_text();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');

			}else{
				if($('#description_'+id).height()>$('#opened_1').height()-$('#opened_imgg').height()-10)	{
					$('#opened_desc p:last-child').append('<span onclick="show_more_text();" id="first_span2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');					 
				}
			}

			if($('#description_'+id).height()<$('#opened_1').height()-$('#opened_imgg').height()-10){
				$('#opened_desc').html($('#description_'+id).html().substr(0,2000));
			}

			$('#opened_desc').css('left',($('#top').width()-950)/2);		
			$('#gallery_ul').anythingSlider(msg.slide);	
			if($('#opened_imgg img').height()+$('#opened_desc').height() < $('#opened_1').height()){
				$('#opened_imgg').css('position','absolute');
				$('#opened_imgg').css('bottom',$('#description_'+id).height()+70);		
			}			
			
		}		
		
	});
	$('#opened_desc').css('bottom','53px');
	
			
	if(!$('#loaded_911').length){
			$.ajax({
			type: "POST",
			url: "/index.php/en/sirens/",
			data: "story_apraksrs=1",	
			dataType: "json",	
			success: function(msg){
				$('#sirens_right').html('<div id="loaded_911"></div>'+msg);
				$('#sirens_right').height($(window).height()-114);
			}
			})
	}		
}
function story_gallery_next(){	
	if($('#show_texts').html()==1){
		$('#opened_desc2').css('height', '29px');
	}
	var total= lists2_ids.length;
	var pos = jQuery.inArray($('#curr_id2').html()+'', lists2_ids);
	pos= pos + 1;
	var name = lists2[pos];
	var id = parseInt(lists2_ids[pos]);
	show_single_img2(name,id);
}
function story_gallery_prev(){
	if($('#show_texts').html()==1){
		$('#opened_desc2').css('height', '29px');
	}
	var total= lists2_ids.length;
	var pos = jQuery.inArray($('#curr_id2').html()+'', lists2_ids);
	pos= pos - 1;
	var name = lists2[pos];
	var id = parseInt(lists2_ids[pos]);
	show_single_img2(name,id);
}
function return_to_story_gallery(){
	$('#opened_desc2').css('height', '29px');
	$('#opened_img2').hide();
	$('#Story_gallery_content .anythingSlider').show();
}
function show_single_img2(name,id){
	$('#Story_gallery_content .anythingSlider').hide();
	//$('#opened_img2').css('height',$('#upload').height());		
	//$('#opened_img2').show();
	
/*
	$.ajax({
		type: "POST",
		dataType: "json",	
		url: "/index.php/en/sirens/",
		data: "image="+name,
		success: function(msg){			
			var Width = 950;
			var Height = $('#Story_gallery').height()-90;
			var BySmallestSide = false;
		
			if (Width){
				var TargetWidth = Width;
				if (Height){
					TargetHeight = Height;
				}else{
					TargetHeight = floor((TargetWidth / msg.width) * msg.height);
				}
			}else if (Height){
				TargetHeight = Height;
				TargetWidth = Math.floor((TargetHeight / msg.height) * msg.width);
			}
			if (Width && Height){
				if ((msg.width / msg.height) > (TargetWidth / TargetHeight)){	
					TargetHeight = Math.floor((TargetWidth / msg.width) * msg.height);
				}else{
					TargetWidth = Math.floor((TargetHeight / msg.height) * msg.width);
				}
			}
					$('#id_holder').html(id);				 
  		
			$('#opened_img2').show('fast', function() {
			
				
			var description = $('#description2_'+id).html();

			$('#opened_desc2').html(description.substr(0,210)+'...');
			if($('#description2_'+id).height()<$('#opened_1a').height()-$('#opened_imgg2').height()-10){
				$('#opened_desc2 p:last-child').append('<span onclick="show_more_text2();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');
			}
			
				if(TargetWidth>msg.height && TargetHeight> msg.height){
					$('#opened_imgg2').html('<img src="/UserFiles/Full/'+ name +'" width="'+ msg.width +'" height = "'+msg.height+'"/><div style="display:none;" id="curr_id2">'+id+'</div>');	
				}else{
					$('#opened_imgg2').html('<img src="/UserFiles/Full/'+ name +'" width="'+ TargetWidth +'" height = "'+TargetHeight+'"/><div style="display:none;" id="curr_id2">'+id+'</div>');	
				}
  			});
  			
  					var total= lists2_ids.length;
			if(!$('#curr_id2').html()){
				var IdToLookFor  = id;			
			}else{
				var IdToLookFor= $('#curr_id2').html();
			}
			var pos = jQuery.inArray(IdToLookFor+'', lists2_ids);

			if(pos==total-1){
				$('#opened_img2 #gal_next').hide();
			}else{
			$('#opened_img2 #gal_next').show();
			}				
			if(pos==1){
				$('#opened_img2 #gal_prev').hide();
			}else{
				$('#opened_img2 #gal_prev').show();
			}				 
  			
  
			if(!$('#opened_img2').length){
				show_single_img(name,id);
			}		
			if($('#show_texts').html()==0){			
				$('#show_texts').html(0);	
				var description = $('#description2_'+id).html();
				$('#opened_desc2').css('height', $('#description2_'+id).height()+'px');			
				$('#opened_desc2').html( description.substr(0,2000));	
				
				if($('#description2_'+id).height()>$('#opened_1a').height()-$('#opened_imgg2').height()-10)	{
					$('#opened_desc2 p:last-child').append('<span onclick="show_more_text2();" id="first_span2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');					 
				}


			}else{
				if($('#description2_'+id).height()>$('#opened_1a').height()-$('#opened_imgg2').height()-10)	{
					$('#opened_desc2 p:last-child').append('<span onclick="show_more_text2();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');					 
				}
			}
			
			if($('#description2_'+id).height()<$('#opened_1a').height()-$('#opened_imgg2').height()-10){			
				$('#opened_desc2').html($('#description2_'+id).html().substr(0,2000));
			}

			$('#opened_desc2').css('left',($('#top').width()-950)/2);		
		}
	});
*/
		//$('#opened_desc2').css('bottom','53px');	
}

function Close_story_gallery(){
	if($('#opened_img2').length){
		$('#opened_img2').hide();
	}
	$('#Story_gallery_closer').hide();
	$('#Story_gallery').hide();
}
function grid(){
	$('#opened_desc').css('height', '29px');
	$('#opened_img').hide();
}
function return_embed2(id,enID){
	$.ajax({
		type: "POST",
		url: "/index.php/en/sirens/",
		dataType: "json",
		data: "emb2="+id+"&enID="+enID,
		success: function(msg){
			$('#overlay_vid').html('');
			$('#overlay_vid').html(msg.msg);
			$('#overlay').height($(document).height());			
			$('#overlay').width($(document).width());						
			var min = $(window).width();
			var hin = $(window).height();
			var me  = $('#overlay_vid').width();
			var me2  = $('#overlay_vid').height();
			$('#overlay_vid').css('margin-left',(min-me)/2);
			$('#overlay_vid').css('margin-top',(hin-me2)/2);
			$('#vid_closer').css('margin-left',(min-me)/2+me-10);
			$('#vid_closer').css('margin-top',(hin-me2)/2-30);

			$('#overlay').show();
			$('#overlay_vid').show();
			$('#vid_closer').show();			
			
		}
	});
}
function return_embed(id){
	$.ajax({
		type: "POST",
		url: "/index.php/en/sirens/",
		dataType: "json",
		data: "emb="+id,
		success: function(msg){
			$('#overlay_vid').html('');
			$('#overlay_vid').html(msg.msg);
			$('#overlay').height($(document).height());			
			$('#overlay').width($(document).width());						
			var min = $(window).width();
			var hin = $(window).height();
			var me  = $('#overlay_vid').width();
			var me2  = $('#overlay_vid').height();
			$('#overlay_vid').css('margin-left',(min-me)/2);
			$('#overlay_vid').css('margin-top',(hin-me2)/2);
			$('#vid_closer').css('margin-left',(min-me)/2+me-10);
			$('#vid_closer').css('margin-top',(hin-me2)/2-30);

			$('#overlay').show();
			$('#overlay_vid').show();
			$('#vid_closer').show();			
			
		}
	});
}
function nex(){	
	if($('#show_texts').html()==1){
		$('#opened_desc').css('height', '29px');
		$('#arrow_2').hide();
		$('#arrow_1').show();
	}
	var total= lists_ids.length;
	var pos = jQuery.inArray($('#curr_id').html(), lists_ids);
	pos= pos + 1;
	var name = lists[pos];
	var id = parseInt(lists_ids[pos]);
	show_single_img(name,id);
}
function pre(){
	if($('#show_texts').html()==1){
		$('#opened_desc').css('height', '29px');
		$('#arrow_2').hide();
		$('#arrow_1').show();		
	}
	var total= lists_ids.length;
	var pos = jQuery.inArray($('#curr_id').html(), lists_ids);
	pos= pos -1;
	var name = lists[pos];
	var id = parseInt(lists_ids[pos]);
	show_single_img(name,id);
}
function uText(){		
		if($('#upload_text').val()=='your 9/11 story'){
			$('#upload_text').val('');
		}
}
function uText1(){		
			if($('#upload_text').val().length==0){
			$('#upload_text').val('your 9/11 story');
		}
		}
function uName(){		
		if($('#upload_name').val()=='your name'){
			$('#upload_name').val('');
		}
		}
function uName1(){	
			if($('#upload_name').val().length==0){
			$('#upload_name').val('your name');
		}

}
function uMail(){	
		if($('#upload_mail').val()=='your e-mail'){
			$('#upload_mail').val('');
		}
}
function uMail1(){
			if($('#upload_mail').val().length==0){
			$('#upload_mail').val('your e-mail');
		}
}

function uTitle(){	
		if($('#upload_title').val()=='title'){
			$('#upload_title').val('');
		}
}
function uTitle1(){
			if($('#upload_title').val().length==0){
			$('#upload_title').val('title');
		}
}


function show_more_text(){
	var id = window.location.hash.substring(2,window.location.hash.length );
	var description = $('#description_'+id).html();	
	var from_bottom = $('#opened_img').height() - $('#opened_1').height();
	if($('#opened_desc').height()==29){
			$('#show_texts').html(0);	
		 $('#opened_desc').animate({height: $('#description_'+id).height()+'px'});			
		 $('#opened_desc').html(description.substr(0,2000));		 
		$('#opened_desc p:last-child').append('<span onclick="show_more_text();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');		 
	}else{
			$('#show_texts').html(1);
		 $('#opened_desc').animate({height: '29px'});
		 $('#opened_desc').html(description.substr(0,190)+'…');		 	
		$('#opened_desc p:last-child').append('<span onclick="show_more_text();" id="first_span2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');		 
	}
}
function show_more_text2(){
	var id = window.location.hash.substring(2,window.location.hash.length );
	var description = $('#description2_'+id).html();	
	if($('#opened_desc2').height()==29){
		$('#show_texts').html(0);	
		var desc_height = $('#description2_'+id).height()+'px';
		 $('#opened_desc2').animate({height: desc_height});					 
		 $('#opened_desc2').html(description);		 
			$('#opened_desc2 p:last-child').append('<span onclick="show_more_text2();" id="first_span2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');		
	}else{
		$('#show_texts').html(1);
		$('#opened_desc2').animate({height: '29px'});
		$('#opened_desc2').html(description.substr(0,190)+'...');		 	
		$('#opened_desc2 p:last-child').append('<span onclick="show_more_text2();" id="first_span">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>');		
	}
}

function previous_storie(){
	var id = window.location.hash;
	$.ajax({
			type: "POST",
			url: "/index.php/en/sirens/",
			dataType: "json",
			data: 'prev_storie='+id,
			success: function(msg){	
				$('.jspPane').html(msg.story);
				$('#story_title').html(msg.title);				
				window.location.hash = 's'+msg.id;			
				if(msg.id==2981){
					$('#story_galery_prev').hide();
					$('#storie_splitter1').hide();		
					$('#story_galery_next').hide();
					$('#story_galery_next2').show();					
				}else{
					$('#story_galery_prev').show();
					$('#storie_splitter1').show();										
					$('#story_galery_next').show();
					$('#story_galery_next2').hide();
				}
								if($('#story_augstumam div').height()<331){
					$('#storie_controls2').hide();				
				}else{
					$('#storie_controls2').show();				
				}
						$('#story_over').jScrollPane({showArrows: true});				
						if($('.jspArrowDown').length){
							$('#scroll_splitter').show();							
						}else{
							$('#scroll_splitter').hide();
						}
			}
		});
}
function scroll(action){
	var top =$('#story_over').css('margin-top'); 		
	if(action==1){		
		if(parseInt(top)<0){
			$('#story_over').css('margin-top',parseInt(top)+10);
		}
	}else{
		if(parseInt(top)-321>-1 * $('#story_over').height()){
			$('#story_over').css('margin-top',parseInt(top)-10);
		}
	}
}
function nextstorie(){
	var id = window.location.hash;
	$.ajax({
			type: "POST",
			url: "/index.php/en/sirens/",
			dataType: "json",
			data: 'next_storie='+id,
			success: function(msg){	
				$('.jspPane').html(msg.story);
				$('#story_title').html(msg.title);				
				window.location.hash = 's'+msg.id;
				if(msg.id==2981){
					$('#story_galery_prev').hide();
					$('#storie_splitter1').hide();		
					$('#story_galery_next').hide();
					$('#story_galery_next2').show();					
				}else{
					$('#story_galery_prev').show();
					$('#storie_splitter1').show();										
					$('#story_galery_next').show();
					$('#story_galery_next2').hide();
				}
				if(msg.last==1){
					$('#story_galery_prev').show();
					$('#storie_splitter1').hide();										
					$('#story_galery_next').hide();
					$('#story_galery_next2').hide();
				}
								if($('#story_augstumam div').height()<331){
					$('#storie_controls2').hide();				
				}else{
					$('#storie_controls2').show();				
				}
					$('#story_over').jScrollPane({showArrows: true});			
		if($('.jspArrowDown').length){
							$('#scroll_splitter').show();							
						}else{
							$('#scroll_splitter').hide();
						}					
			}
		});			
}

function show_more_comment(id){
	var fullComment = $('#comment-'+id+'_full').html();
	$('#comment-'+id+'_short').html(fullComment.substr(0,fullComment.length)+'<span class="show_less_comment" onclick="show_less_comment('+id+');"><img src="http://lauriegarrett.com/Elements/Public/Entry/Style/Images/a_up.png" alt="show less"/></span>');	
}
function show_less_comment(id){
	var fullComment = $('#comment-'+id+'_full').html();
	$('#comment-'+id+'_short').html(fullComment.substr(0,159)+'...<span class="show_more_comment" onclick="show_more_comment('+id+');"><img src="http://lauriegarrett.com/Elements/Public/Entry/Style/Images/a_down.png" alt="show more"/></span>');
}
function send(){
	name = mail  = msg = title = utitle = false;
	if($('#upload_name').val().length!=0 && $('#upload_name').val()!='your name'){
		var name= true;
	}else{
		var name= false;
	}
	if(isValidEmailAddress( $('#upload_mail').val() )  && $('#upload_name').val()!='your e-mail'){
		var mail= true;
	}else{
		var mail= false;
	}
	if($('#upload_text').val().length!=0 && $('#upload_text').val()!=='your 9/11 story'){
		var msg= true;
	}else{
		var msg= false;
	}
	
	if($('#upload_title').val().length!=0 && $('#upload_title').val()!=='title'){
		var utitle= true;
	}else{
		var utitle= false;
	}	
/*
	if($('#title').val().length!=0){
		var title= true;
	}else{
		var title= false;
	}	
*/		
	if(name && mail && msg && utitle){
		$('#publish').hide();
			$.ajax({
			type: "POST",
			url: "/index.php/en/sirens/",
			dataType: "json",
			data: $('#upload_form').serialize(),
			success: function(msg){
				if(msg=='OK'){	
					$('#upload_name').val="your name";
					$('#upload_mail').val="your e-mail";
					$('#upload_text').val="your 9/11 story";	
					$('#upload_left').html('<div style="position:absolute;bottom:0;right:0;padding:17px;">Story received. You will get notification on given e-mail when it is published on the site. Thank you for sharing.</div>');
				}
				else{
					$('#upload_err').html('Error, please reload page and try again!')
					$('#upload_err').show();
															
				}
			}
	});

	}
	else{
	
		if(!name){
			$('#upload_name').css('border-color','red');		
		}else{
			$('#upload_name').css('border-color','#8F8F8F');	
		}
		if(!mail){
			$('#upload_mail').css('border-color','red');		
		}else{
			$('#upload_mail').css('border-color','#8F8F8F');	
		}	
		if(!msg){
			$('#upload_text').css('border-color','red');		
		}else{
			$('#upload_text').css('border-color','#8F8F8F');	
		}	
		if(!utitle){
			$('#upload_title').css('border-color','red');		
		}else{
			$('#upload_title').css('border-color','#8F8F8F');	
		}		
		/*
if(!title){
			$('.qq-upload-button').css('border-color','red');		
		}else{
			$('.qq-upload-button').css('border-color','#8F8F8F');	
		}					
*/
	}

}

