/*
 * General config
 * By poppo 
 * E-Mail: pop@silvermover.com
 * November 2010
 */

$(function(){
	var bgSlideComplete=false;
	
	if($.browser.msie)
	{
		if($.browser.version<7)
		{
			$('.logoBlog  a img').attr('src',$url+'images/logo.jpg');
			$('.content').css({'backgroundImage':'none','background':'#000'});
		}
	};
	
	$('.topMenu a,.footerMenu a').hover(
		function(){
			$(this).parent().addClass('menuHover');
		},function(){
			$(this).parent().removeClass('menuHover');
		}
	);
	
	$('#toggleContent').live('click',function(){
		var me=$(this);
		var parent=me.parent();
		if(parent.height()>=36)
		{
			$('.jScrollPaneContainer').slideUp(800, function(){
				parent.animate({'height':'35px'},800,function(){});
				me.addClass('toggleOn').html('open');
			});
		}else{
			parent.animate({'height':'620px'},800,function(){
				$('.jScrollPaneContainer').slideDown(800,function(){
				me.removeClass('toggleOn').html('close');	
				});
			});
		}
		
		return false;
	}).html('close');
	

		$('.topMenu a,.footerMenu a, .link2page').live("click",function(){
			var href=$(this).attr('rel');
				
			if(location.hash=="" || location.hash!= '#'+href)
			{
				location='#'+href;
			}
			return false;
		});
		
		$(window).hashchange( function(e){
			var hash=location.hash;
			if(hash!="")
			{
				changePages(hash);
			}
		  });
		/*
		$('.showThumbnail .thumb a').live('click',function(){
			
			var rel=$(this).attr('rel');
			$('.content').animate({height:'20px'},800,function(){
			$(this).html('<img src="'+$url+'images/ajax-loader.gif" alt="loading..." id="ajaxLoader" style="margin:10px 0 0 40%" \/>');
			
				$.getJSON($url+"ajax.html",{flag:'album',tag:rel},function(data){
					alert(data.html);
					$('body').scrollTo(200);
					$('.content').animate({height:'620px'},800,function(){
						$(this).html(data.html).hide().fadeIn(800,function(){
							$('#toggleContent').html('close');
							setScrollPane('.contentInner');
						});
					});
				});
			});
			return false;
			
			});*/
		
		
		
		
		
		
		function changePages(tag)
		{
			var hash=tag;
			var isIE=$.browser.msie;
			$('.topMenu a,.footerMenu a').removeClass('active');
				
			var rel=hash.substr(1);
			$('.topMenu a[rel="'+rel+'"],.footerMenu a[rel="'+rel+'"]').addClass('active');
			
			if(isIE)
			{
				if($.browser.version<9){
					changePage4ltIE9(hash,rel);
				}else{
					changePage4ModernBrowser(hash,rel);
				}
			}else{
				changePage4ModernBrowser(hash,rel);
			}
		}
		
		function changePage4ltIE9(hash,rel)
		{
			$('.content').animate({height:'20px'},800,function(){
			$(this).html('<img src="'+$url+'images/ajax-loader.gif" alt="loading..." id="ajaxLoader" style="margin:10px 0 0 40%" \/>');
			$('.topMenu a[rel="'+rel+'"],.footerMenu a[rel="'+rel+'"]').addClass('active');
				$.getJSON($url+"ajax.html",{flag:'content',hash:hash},function(data){
					var container=$('#containerBG');
					container.attr('class','');
					container.addClass(data.style).addClass("containerBlog");
					$('body').scrollTo(200);
					$('.content').animate({height:'620px'},800,function(){
						$(this).html(data.html).hide().fadeIn(800,function(){
							setScrollPane('.contentInner');
							bgSlideComplete=true;
							$('#toggleContent').html('close');
						});
					});
				});
			});
		}
		function changePage4ModernBrowser(hash,rel)
		{
			$('.content').animate({height:'20px'},{duration:800,easing:'bounceout',complete:function(){
			$(this).html('<img src="'+$url+'images/ajax-loader.gif" alt="loading..." id="ajaxLoader" style="margin:10px 0 0 40%" \/>');
				$.getJSON($url+"ajax.html",{flag:'content',hash:hash},function(data){
					$('title').html(data.title);
					$('#containerBG').animate({backgroundPosition:"(-923px 0px)"}, {duration:500, complete:function(){
						var container=$('#containerBG');
						container.attr('class','');
						container.addClass(data.style).addClass("containerBlog");
						$('#containerBG').animate({backgroundPosition:"(0px 0px)"}, {duration:800,complete:function(){
							$('.content').html(data.html).animate({'height':'620px'},{duration:800,easing:'bounceout'});
							$('body').scrollTo(200);
							setScrollPane('.contentInner');
							bgSlideComplete=true;
							containerBackgroundDefault();
							$('#toggleContent').html('close');
						}
						});
						
							
					}
					});	
				});
			}});
		}
		function containerBackgroundDefault(){
			if($('#containerBG').css('backgroundPosition')!='0px 0px'){
				$('#containerBG').css('backgroundPosition','0px 0px')
			}else{
				bgSlideComplete=true;
			}
		}
		function setScrollPane(elem)
		{
			$(elem).jScrollPane({showArrows:false, dragMaxHeight:40, autoReinitialise: true});
		}
		/* Trigger the event (useful on page load). */
		$(window).trigger('hashchange');
	
		preloadBackgroundImages(backgroundImagesPreload);	
		$(window).load(function(){
			$('.contentInner').jScrollPane({showArrows:false, dragMaxHeight:40});
		});
}); /* n doc */

/* plugin Scrolling page */
$.fn.extend({scrollTo:function(speed,easing){return this.each(function(){var targetOffset=$(this).offset().top;$('html,body').animate({scrollTop:targetOffset},speed,easing);});}});

function preloadBackgroundImages(args){if(document.images){if(!document.imageArray) document.imageArray = new Array();/*var i,j = document.imageArray.length, args = preloadImages.arguments; */var i,j = document.imageArray.length;var path;for(i=0; i<args.length; i++){if (args[i].indexOf("#")!=0){path=$url+args[i];document.imageArray[j] = new Image;document.imageArray[j++].src = path;}}}} /* n fnc */
