$colors=new Array('#ffcc00','#33333', '#cc00ff','#00ccff','#cfa030');


$numCurrent=100;
$changeColor=true;
 $("#home").mousemove(function(e){
 
    moveAnimation()
});

function moveAnimation(){
	  $numRandom = Math.floor(Math.random()*6)
	  
	 
	 if($changeColor==true && $numCurrent!=$numRandom){
		
		$changeColor=false
		$('#mask').stop().animate({
		
			backgroundColor: $colors[$numRandom]
		}, 400, function() {
			$numCurrent=$numRandom;
			$changeColor=true;

		});
		}

$changeColor=true;
}

jQuery(function( $ ){
	/**
	 * Demo binding and preparation, no need to read this part
	 */
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout =  function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	};
	
	
	$.easing.easeInOutBounce= function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	}


});




$('.section').click(function(){
	
	$(this).find('img').fadeIn(1000);
});





$('.active-ar .show-btn.first').live('click', function(){
	$(this).parent().find('section.first').fadeIn(1000);
	$(this).parent().find('section.second').fadeOut(1000);
	loadShowImg('.first',$(this))
	
	
	//alert('jo')
	return false;
})



$('.active-ar .show-btn.second').live('click', function(){
	$(this).parent().find('section.second').fadeIn(1000);
	$(this).parent().find('section.first').fadeOut(1000);
	loadShowImg('.second',$(this))
	//alert('jo')
	return false;
})

$('#grey.active-ar .show-btn').live('click', function(){
	$(this).parent().find('section').fadeIn(1000);
	
	
	//alert('jo')
	return false;
})



$('.active-ar .next-show-btn').live('click', function(){
	
	$('.active-ar .show-btn.second').click()
	return false
});

$('.active-ar .prev-show-btn').live('click', function(){
	
	$('.active-ar .show-btn.first').click()
	return false
});



$('.active-ar .hide-btn').live('click', function(){
	if($('#grey').hasClass('active-ar')==true){
		$(this).parent().fadeOut(1000);
	}else{
		$(this).parent().parent().fadeOut(1000);
   }
	//alert('jo')
	return false;
})


$(document).keyup(function(e) {
 
  if (e.keyCode == 27) { $('.active-ar section').hide(); }   // esc
  else if(e.keyCode == 37) { $('.active-ar .prev-show-btn').click(); }   // esc
  else if (e.keyCode == 39) { $('.active-ar .next-show-btn').click(); }   // esc
   else if(e.keyCode == 38) { $('#prev-btn').click(); return false}   // esc
  else if (e.keyCode == 40) { $('#next-btn').click(); return false}   // esc
  
});





$(window).scroll(function () { 
	$sh=$(window).height()
	$st=$(window).scrollTop()+$(window).height()
		
	
	$ws=$sh*2-($sh/2)
	$ys=$sh*3-($sh/2)
	$gs=$sh*4-($sh/2)
	$rs=$sh*5-($sh/2)
	$bs=$sh*6-($sh/2)
	$os=$sh*7-($sh/2)
	$grs=$sh*8-($sh/2)
	
	if($ws>$st){
		
		if(!($("#prev-btn").hasClass('disabled-btn'))){
			$('#prev-btn').addClass('disabled-btn');
		}
		$('#white').addClass('active-ar');
		$('#yellow').removeClass('active-ar');
		
	}else if ($ys>$st){
		$('#prev-btn, #next-btn').removeClass('disabled-btn');
		$('#yellow').addClass('active-ar');
		$('#white').removeClass('active-ar');
		$('#green').removeClass('active-ar');
		
	}else if ($gs>$st){
		
		$('#green').addClass('active-ar');
		$('#yellow').removeClass('active-ar');
		$('#red').removeClass('active-ar');
	}else if ($rs>$st){
		
		$('#red').addClass('active-ar');
		$('#green').removeClass('active-ar');
		$('#blue').removeClass('active-ar');
	}else if ($bs>$st){
	
		$('#blue').addClass('active-ar');
		$('#red').removeClass('active-ar');
		$('#orange').removeClass('active-ar');
	}else if ($os>$st){
		$('#prev-btn, #next-btn').removeClass('disabled-btn');
		$('#orange').addClass('active-ar');
		$('#blue').removeClass('active-ar');
		$('#grey').removeClass('active-ar');
		
	}else if ($grs>$st){
		
		$('#grey').addClass('active-ar');
		$('#orange').removeClass('active-ar');
		$('#next-btn').addClass('disabled-btn');
	}
	
 


});

$totallArticles=7
$('#next-btn').live('click', function(){
	
	
	$currentArticleNo=$('.active-ar').index('article')
	
	
	if($currentArticleNo<$totallArticles){
	
	
		$nextArticle=$('.active-ar').next()
		$currentArticle=$('.active-ar');
	
		$.scrollTo( $nextArticle, 1500, {axis:'y', easing:'elasout' }); 
	
		$('.active-ar').next().addClass('active-ar');
	 	$currentArticle.removeClass('active-ar');
	 }else{
		$('#next-btn').addClass('disabled-btn');
		 
	 }
	
	  $('#prev-btn').removeClass('disabled-btn');
	 
 	return false;
});
$('#prev-btn').live('click', function(){
	//
	
	$currentArticle=$('.active-ar')
	$prevArticle=$('.active-ar').prev()
	
	
	//alert($('body').find('aricle .active-ar').prev().attr('class'));
	$.scrollTo($prevArticle, 1500, {axis:'y', easing:'elasout' });
	$('.active-ar').prev().addClass('active-ar');
	 $currentArticle.removeClass('active-ar');
	//$('.active-ar').removeClass('active-ar');
	
 	return false;
});


function scaleImages(){
	$marginPercent=10
	$margin=Math.round($marginPercent/100*$(window).height())
	$marginBottom=$margin/2
	$marginTop=$margin/2
	
	$containerHeight=$(window).height()-$margin
  
	
	if($largeImg=='large'){
		$imgWidth=720;
		$imgHeight=1080;
	}else{
		$imgWidth=960;
		$imgHeight=1440;
	}
	$marginPercentScaleH=Math.round(($containerHeight/$imgHeight)*100);
	
	$scaleImgHeight=Math.round(($marginPercentScaleH/100*$imgHeight))
	$scaleImgWidth=Math.round(($marginPercentScaleH/100*$imgWidth))
	
	
		
	$descWidth=Math.round(55/100*$scaleImgWidth)
	$containerWidth=$scaleImgWidth*2 +$descWidth
	$('.description').css('width', $descWidth)
			
		
	if($(window).width()<1024){
		
		$descWidth=Math.round(45/100*$scaleImgWidth)
		$containerWidth=$scaleImgWidth*2 +$descWidth
		$('.description').css('width', $descWidth)
		$('.apsolute-position').css('left', $scaleImgWidth*2)
	}
	if (($containerWidth+($containerWidth/3))>$(window).width()){
		$('.description').addClass('apsolute-position')
		$('.apsolute-position').css('left', $scaleImgWidth*2)
	}else{
		$('.description').removeClass('apsolute-position')
		$('.description').css('left',0 )
	}
	
	
	
	$('article section .show-img').css({'height': $scaleImgHeight,'width': $scaleImgWidth})
	$('article section').css({'height': $scaleImgHeight,'width': $containerWidth, 'marginLeft':-($containerWidth/2)})
}

var $largeImg=false
$(document).ready(function() {
	scaleImages()
	$sh=$(window).height()
	$st=$(window).scrollTop()+$(window).height()
	
	//preload large Images
	if(screen.height>=1200){
		 
		$largeImg='large';
	}
	
	$preloadMainImg=$('.preload-img');
	$preloadMainImg.each(function(i) {
		if($('body').attr('id')=='sr'){
			$($('article')[i]).append('<img class="loader" src="/img/04/loader-sr.gif" />')
		}else{
			$($('article')[i]).append('<img class="loader" src="/img/04/loader-en.gif" />')	
		}
		
		var $imgSrc= $($preloadMainImg[i]).attr('href');
	
		if($largeImg=='large'){
			$imgSrc= $($preloadMainImg[i]).attr('href').split('/');	
			$imgSrc='/'+$imgSrc[1]+'/'+$imgSrc[2]+'/'+$largeImg+'/'+$imgSrc[4];
		}
		
	var img = new Image();
		$(img)
    .attr({
		'src': $imgSrc,
		'class': 'main-img' 
		})
    .load(function(){
        $($('article')[i]).append( $(this) );
		$($('article')[i]).find('.loader').remove();
		$($('article')[i]).find('.show-btn.first,.show-btn.second').fadeIn(2000)
		$(this).fadeIn(2000);
		$('.main-img').css('marginLeft',(-($('.main-img').width())/2));
        // Your other custom code 
    });
})
	
	
});

$(window).bind("resize", function(){ 
	$sh=$(window).height()
	$st=$(window).scrollTop()+$(window).height()
	scaleImages()
	$('.main-img').css('marginLeft',(-($('.main-img').width())/2));
})


function loadShowImg(order,o){
	
	var $otherImg=o.parent().find(order+' .show-img a');
	
	var loader=$('.active-ar section'+order).find('.show-img')
	$otherImg.each(function(i) {
	
	var $imgSrc=	$($otherImg[i]).attr('href')
	if($largeImg=='large'){
			$imgSrc= $($otherImg[i]).attr('href').split('/');	
			$imgSrc='/'+$imgSrc[1]+'/'+$imgSrc[2]+'/'+$largeImg+'/'+$imgSrc[4];
		  
	}	
	
	if($(loader[i]).find(".shown-img").length == 0){
	
		
		if($('body').attr('id')=='sr'){
			$(loader[i]).append('<img class="loader" src="/img/04/loader-sr.gif" />')
		}else{
			$(loader[i]).append('<img class="loader" src="/img/04/loader-en.gif" />')	
		
	
		}
		$('<img />')
		.attr({
			'src': $imgSrc,
			'class': 'shown-img' 
			})
		.load(function(){
			$($('.active-ar section'+order).find('.show-img')[i]).append($(this));
			 $($('.active-ar section'+order).find('.show-img')[i]).find('.loader').remove()
			
			//var removeLoader= $($('section'+order)).find('.loader')
			//$(removeLoader[i]).empty().fullRemove();
			
			$(this).fadeIn(2000);
			
			// Your other custom code 
		 });
	}
})
}



 
$('a[href^="http://"]').addClass("external").attr({ target: "_blank" });





$(function() {
    var delay = 400;
    
    function hideMenu() {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden')) {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }
    
    $('.custom_button, .hover_menu').mouseenter(function() {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function() {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });    
    
});


if ( $.browser.msie ) {
   

$('#like-btn').hover(function () {

	 
	$('#like-wrap').css('display','block');
},
  function () {
    $('#like-wrap').css('display','none');
  }



)

$('#twitt-btn').hover(function () {

	 
	$('#twitt-wrap').css('display','block');
},
  function () {
    $('#twitt-wrap').css('display','none');
  }



)
 }

/*
$('<img />')
    .attr({
		'src': '/img/04/2.jpg',
		'class': 'main-img' 
		})
    .load(function(){
        $('.white').append( $(this) );
		$(this).fadeIn(2000);
		
        // Your other custom code 
    });











$preloadMainImg=$('.preload-img');
var $imgSrc=new Array();
$preloadMainImg.each(function(i) {
		$imgSrc[i]=$($preloadMainImg[i]).attr('href');
		
	})

alert($imgSrc);

$('<img />')
    .attr({
		'src': '/img/04/2.jpg',
		'class': 'main-img' 
		})
    .load(function(){
        $('.white').append( $(this) );
		$(this).fadeIn(2000);
		
        // Your other custom code 
    });
*/
