﻿var $j = jQuery.noConflict();

	/* ==== gallery categories (HOME PAGE) ==== */
	function GalleryBoxLoading()
	{
		var cats = $j('.img_cat');
	
		cats.each(function(){
			
			var loader = $j(this).find('a');
			
			var imgURL = loader.attr('title');
			
			var img = new Image();
			
			$j(img).css('opacity', '0.0').load( function(){
			
				loader.append(this).removeAttr('title');
				
				$j(this).animate({opacity: 1.0}, 500, function()
					{
						loader.find('span').animate({opacity: 0.9}, 500);
					}
				);
			
			}).attr('src', imgURL);
			
		});
		
		$j('#oncatlist li').each(function(){
			
			var loader = $j(this).find('a');
			
			var imgURL = loader.attr('title');
			
			var img = new Image();
			
			$j(img).css('opacity', '0.0').load( function(){
			
				loader.append(this).removeAttr('title');
				
				$j(this).animate({opacity: 1.0}, 500, function()
					{
						loader.find('span').animate({opacity: 0.9}, 500);
					}
				);
			
			}).attr('src', imgURL);
			
		});		

	}
	
	function doFullScroll()
	{
		var maxWidth = $j(window).width();
		var maxHeight = $j(window).height();
		
		var topHeight = $j('#verytop').height();
		var marginNow = maxHeight - 140;
		
		$j('#album-cat').css("width", maxWidth + "px").css("display", "block").animate({top : marginNow / 2 + "px"}, 1000);		
		
				$j.fn.hoverscroll.params = $j.extend($j.fn.hoverscroll.params, {
					width: maxWidth,
					height: 140,
					arrows: true
				});	
				
				$j('#oncatlist').hoverscroll();			
	}
	
	function doCloseScroll(){
		$j('#album-cat').animate({top : "-160px"}, 1000,
			function()
			{
				$j('.listcontainer').scrollLeft(0);
				$j(this).css('display', 'none').css('width', '0px');
				$j('#sidecat').animate({left : '0px'}, 200);
			}
		);
	}

	function OpenCatBar(){
		$j('#sidecat a').click( function()
		{
			doFullScroll();
			$j(this).parent().animate({left : '-30px'}, 200);
			return false;
		}
		);
		
		$j('#closebar').click( function()
		{
			doCloseScroll();
			
			return false;
		}
		);		
	}
	
			var postStart = function() {
			   var $poststarted,
				   $poststoped;
			   return {
					$poststarted : function(){
						$poststarted = setInterval("Change_Next()", 250); 
						},  
					$poststoped : function(){
					   clearInterval($poststarted);
					}
			   }
			}();
		 
			function Change_Next(){
						
						var $active = $j('#postlists li.done');
						if ($active.length == 0) {
							$next = $j('#postlists li.postlist:first');
						}	
						var $next =  $j('#postlists li.done:last').next("li").length ? $j('#postlists li.done:last').next("li")
						: $j('#postlists li.postlist:first');   
						if($active.length == $j('li.postlist').length){	
							postStart.$poststoped();
						} else {
							
							nowChange($next);
						}	
			}

			function nowChange($next){
					$next.addClass('done')
					
					var bloader = $next.find('a');
					
					var bimgURL = $next.attr('title');
					
					var img = new Image();
					
					$j(img).css('opacity', '0.0').load( function(){
					
						bloader.append(this);
						
						$next.removeAttr('title');
						
						$j(this).animate({opacity: 1.0}, 300,
										function()
										{
											bloader.css("background", "#000000");
											$j(this).animate({opacity: 0.4},200);
										}
									);
					
					}).attr('src', bimgURL);
			}	
	
	
	function PostLoad()
	{
			
			if( ($j('.postlist').length) != 0 ){
				postStart.$poststarted();
				
				Change_Next();			
			}
	}


	function onItemHover()
	{

						$j('.postlist a').hover( function()
						{		
							var span = $j(this).find('span');
							$j(this).find('img').stop(true, true).animate({ opacity : 1}, 300,
								function(){
									span.animate({width : "50px"}, 150);
								}
							);

						}, function() {
							var span = $j(this).find('span');
							$j(this).find('img').stop(true, true).animate({ opacity : 0.4}, 300,
								function(){
									span.animate({width : "0px"}, 100);
								}							
							);

						});
	
	}
	
	function ContactHandle()
	{
		$j('#hsub').click( function() {
		
			var name = $j('#hname').val();
			var mail = $j('#hmail').val();
			var subs = $j('#hsubj').val();
			var mess = $j('#hmess').val();
			
			if (name != "" && mail != "" && subs != "" && mess != "")
				{
						var bgh = $j('#hasil');
						var uril = $j("meta[name=info_url]").attr('content');
						var ppp = $j(this).parent('.ajload');
						
					
					ppp.html('<div class="m-load"></div>');
					
					$j.ajax(
						{
							url: uril,
							type: 'GET',
							data: "hname=" + name + "&hmail=" + mail + "&hsubj=" + subs + "&hmess=" + mess ,
							success: function(result) 
							{
							
								$j('#hsub').fadeIn(500);
								$j('.input, #hmess').val("");
								ppp.html('<input type="submit" name="submit" id="hsub" value="Send Message" />');
								bgh.fadeIn(500).html("" + result + "").delay(1000).fadeOut('slow');
								
							}
						}
					);
					return false;
					
				} 
			else 
				{
					alert('Please complete all required fields!');
					return false;
				}
			
		});
		
	}	
	
	function doCufont(){
	
		Cufon.replace(".img_cat span, #oncatlist span, h1, h2, h3, h4, h5, h6", {fontFamily: 'ColaborateLight'});
		Cufon.replace("#nav a, .icip", {fontFamily: 'Bebas', hover : true});
	
	}
	
	function menuHover(){
		
		$j('#nav a').hover( function()
		{
			
			var popup = $j(this).parent('li').find('.page-description');
			
			popup.css('opacity', '0').css('display', 'block').stop(true, true).animate(
				{
					opacity : 1.00
				}, 300 );
			
		}, function()
		{
			var popup = $j(this).parent('li').find('.page-description');
			
			popup.stop(true, true).animate(
				{
					opacity : 0
				}, 300, function ()
				{
					$j(this).hide();
				});		
		});
	}
	
	function pageStyle(){
		var toStyle = $j("#mid-page");
		var veryTops = $j('#verytop').height();
		var titleHeights = $j('.singletitlewrap').height();		
		
		toStyle.css('margin-top', titleHeights + 15 + "px").css('margin-bottom', veryTops + 15 + "px");
		
	}
	
$j(document).ready(function(){
	GalleryBoxLoading();
	menuHover();
	OpenCatBar();
	doCufont();
});