// Home page Rolling River


function go ( )
{// (do something here)
	var rand=Math.floor(Math.random()*8);
	
	switch(rand)
		{
		case 0:
			dance("blog", 300);
		  break;
		case 1:
			dance("twitter", 300);
		  break;
		case 2:
			dance("linkd", 300);
		  break;
		case 3:
		caser("portfolio", 300);
		  break;
		case 4:
		caser("casestudy", 300);
		  break;
		case 5:
		caser("blogPhotos", 300);
		 break;
		case 6:
			dance("linkd", 300);
			break;
		case 7:
			dance("linkd", 300);
			
		break;
		default:
		 // console.log("NULL");
		}
}
var count=0;
function go2 ( )
{// (do something here)
		
	switch(count)
		{
		case 0:
			dance("blog", 300);
		  break;
		case 1:
			caser("portfolio", 300);
		  break;
		case 2:
		dance("twitter", 300);
			
		  break;
		case 3:
		caser("casestudy", 300);
			
		  break;
		case 4:
		dance("linkd", 300);
			
		  break;
		case 5:
		caser("blogPhotos", 300);
		break;
		case 6:
		dance("linkd", 300);
		break;
		case 7:
		dance("linkd", 300);
			
		break;
		default:
		 // console.log("NULL");
		}
		count = (count<6)? count+1: 0;
}

function dance(selection, t){
	newX = 274;
	$("#"+selection+" > .cont").animate({marginLeft: "-=" + newX + "px"}, 
								{duration:t, complete:function(){
									$(this).children(".capsul").first().detach().appendTo($(this));
									$(this).css("marginLeft", 0);
								}
							});
}
function caser(selection, w){
	newX = parseInt($("#"+selection+" > .outermask > .mask").children(".imgStream").first().css("width"));
	$("#"+selection+" > .outermask > .mask").animate({
                              marginLeft: "-=" + newX + "px"
                        }, {duration:w, complete:function(){
							$(this).children(".imgStream").first().detach().appendTo($(this));
							$(this).css("marginLeft", 0);
							}});
}

(function loop(){


go();

setTimeout(loop, 2000);

})()

$(document).ready(function(){

// Home page Hover Icons

	$(".hicon").hide();
	$(".storyHover").hide();
		
	var offset = $(window).width()/2-492;
    
    $(".sparklogo").mousemove(function(h){
        $(".hlogo").stop().fadeTo('fast','1.0');
        $(".hlogo").css({
            top: (h.pageY - 330) + "px",
            left: (h.pageX - offset - 16) + "px",
        });
    });
	$(".sparklogo").mouseout(function(e){
   		$(".hlogo").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
	
	$(".sparklinked").mousemove(function(h){
        $(".hlinked").stop().fadeTo('fast','1.0');
        $(".hlinked").css({
            top: (h.pageY - 320) + "px",
            left: (h.pageX - offset - 20) + "px",
        });
    });
	$(".sparklinked").mouseout(function(e){
	    $(".hlinked").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
	});

    $(".sparkprocess").mousemove(function(h){
        $(".hprocess").stop().fadeTo('fast','1.0');
        $(".hprocess").css({
            top: (h.pageY - 320) + "px",
            left: (h.pageX - offset - 20) + "px",
        });
    });
    
    $(".sparkprocess").mouseout(function(e){
        $(".hprocess").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
    
    $(".sparkport").mousemove(function(h){
        $(".hport").stop().fadeTo('fast','1.0');
        $(".hport").css({
            top: (h.pageY - 320) + "px",
            left: (h.pageX - offset - 20) + "px",
        });
    });
    
    $(".sparkport").mouseout(function(e){
        $(".hport").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
    
    $(".sparkblog").mousemove(function(h){
        $(".hblog").stop().fadeTo('fast','1.0');
        $(".hblog").css({
            top: (h.pageY - 320) + "px",
            left: (h.pageX - offset - 20) + "px",
        });
    });
    
    $(".sparkcontact").mouseout(function(e){
        $(".hcontact").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
    
    $(".sparkcontact").mousemove(function(h){
        $(".hcontact").stop().fadeTo('fast','1.0');
        $(".hcontact").css({
            top: (h.pageY - 320) + "px",
            left: (h.pageX - offset - 20) + "px",
        });
    });
    
    $(".sparkblog").mouseout(function(e){
        $(".hblog").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
	
	 $(".sparkgreenlight").mousemove(function(h){
        $(".sgreen").stop().fadeTo('fast','1.0');
        $(".sgreen").css({
            top: (h.pageY + 5) + "px",
            left: (h.pageX + 5) + "px",
        });
    });
    
    $(".sparkgreenlight").mouseout(function(e){
        $(".sgreen").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });
	
	$(".sparkneutral").mousemove(function(h){
        $(".sneutral").stop().fadeTo('fast','1.0');
        $(".sneutral").css({
            top: (h.pageY + 5) + "px",
            left: (h.pageX + 5) + "px",
        });
    });
    
    $(".sparkneutral").mouseout(function(e){
        $(".sneutral").stop().fadeTo('fast','0.0',function(){ $(this).hide();});
    });

$(window).resize(function() {

if($(window).width() <985){
	offset = 0;
}else{
	offset = $(window).width()/2-492;
}
	
    // console.log( $(window).width()/2-492);
	// console.log( $(".mainText").css("left"));
});


// Home page Portfolio hover states

$(".port").hover(function(){

	$("#portfolio .outermask").stop().animate({top: -25, height: 140}, 500);
},function(){

	$("#portfolio .outermask").stop().animate({ top: 0, height: 90}, 200);
});

$(".case").stop().hover(function(){

	$("#casestudy .outermask").stop().animate({top: -25, height: 140}, 500);
},function(){

	$("#casestudy .outermask").stop().animate({ top: 0, height: 90}, 200);
});




// Blog stripping

$(".mainText span").attr("style","");
  
  
$(".feature").each(function(i){
    $(this).find("img").each(function(j){
      if(j>0){  
        $(this).hide();    
      }
	})
	;
});


// Top it!
  
    $('.topit').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });


// Select SEARCH bar text
$('#keywords').click(function() {
  $('#keywords').select();
});




// H2 Vertical Centering

// $('.titleinner').each(function(i){ $(this).css("marginTop", -$(this).height()/2)  });


// RC Height adjusting
setTimeout("resizer()", 5000);



});// END JQUERY 


// MISC Scripts


function resizer(){

var caseHeight = $("#mainCaseBody").height();
var blogHeight = $("#mainBlogBody").height();


if(caseHeight > ( $("#rc").height() ))
    {
        $("#rc").css("height", caseHeight+"px");
	}
	
if(blogHeight > ( $("#rc").height() ))
    {
      $("#rc").css("height", blogHeight+"px");
	}
}

// newslet pop

var win= null;
function OpenNewWindow(mypage,w,h,myname){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
settings='height='+ h +',width=' +w+ ',top=' +wint+ ',left='+ winl+ ',scrollbars=no,toolbar=no'
win=window.open(mypage,myname,settings)
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}



