/*

           ::::::::  :::::::::: ::::::::   ::::::::  ::::    ::: :::::::::  
          :+:    :+: :+:       :+:    :+: :+:    :+: :+:+:   :+: :+:    :+: 
          +:+        +:+       +:+        +:+    +:+ :+:+:+  +:+ +:+    +:+ 
          +#++:++#++ +#++:++#  +#+        +#+    +:+ +#+ +:+ +#+ +#+    +:+ 
                 +#+ +#+       +#+        +#+    +#+ +#+  +#+#+# +#+    +#+ 
          #+#    #+# #+#       #+#    #+# #+#    #+# #+#   #+#+# #+#    #+# 
           ########  ########## ########   ########  ###    #### #########  

     ::::::::   ::::::::  :::    :::  :::::::: ::::::::::: ::::    :::  ::::::::  
    :+:    :+: :+:    :+: :+:    :+: :+:    :+:    :+:     :+:+:   :+: :+:    :+: 
    +:+        +:+    +:+ +:+    +:+ +:+           +:+     :+:+:+  +:+ +:+        
    +#+        +#+    +:+ +#+    +:+ +#++:++#++    +#+     +#+ +:+ +#+ +#++:++#++ 
    +#+        +#+    +#+ +#+    +#+        +#+    +#+     +#+  +#+#+#        +#+ 
    #+#    #+# #+#    #+# #+#    #+# #+#    #+#    #+#     #+#   #+#+# #+#    #+# 
     ########   ########   ########   ######## ########### ###    ####  ########  


                /           /       / /  /      /     /  /       / /
                    / /      /    /   /     ===================  
                         /    /   /___  /    secondcousins.org   /
                  /   /       /  ,;(  /-,   ===================
                    /      /    /(((\   (    /   /  /    /   /
                /      /      / \\\\(.__,'           /       /   /
                   /  /   /     /\)\\:._`.__/   /      /   /
                / /     /   /    ,)'        `._   /     /    /
                     /         ,'           \  `-..___)\__,,     /
                 /       /  ,-'    ,         `._     (__.-'   /
                 ,.-'`,_..-'    .-' \         \ ``---''   /
                /  ``-/      _.-'   / \         `. /    /       /
                 /   ``---''    /     \       _,(   /      /
                      /     /           \ _.-''   \ /   /     /
                  /   /      /    /  /  (     .   \      /  
                        /        /       \     \   \ /    /    /
                /  /    /     /      /   / )     )   )    /    
                          /     /     _/_/     /   /  /    /    /
                /  _/__...---/--'''/''  /     /   /```--/-..._/__
                  < >   _.-.    -   _  /    _(  _(_   - _   < >  
                      .   _-  <  >   -'..-''  `'   .-     _   .
                   `--...__     .-.  __.   <  >      <  >
                           ``---..__        ..-._  .   _.-.   <  >
                                    ```----....-._________________   
                                                      
*/
$(document).ready(function() {

	//make shit repeat
	String.prototype.repeat = function(num){
		return new Array(num + 1).join(this);
	};

	//initiailse everything
	function init(){

		//run infinite colour changing
		

		var winheight = $(window).height()/2;
		var winwidth = $(window).width()/2;
		var conheight = 390/2;
		var conwidth = $('.container').outerWidth()/2;

		//tumblr position logo correctly - rewrite in css
		$('.logo').css({top:winheight-conheight, left:winwidth-conwidth});

		var hue = getColour();
		//on load show the shiz
		$('.splash').css({backgroundColor:hue}).fadeIn(700).delay(2000).fadeOut(700);
		$('.container, .bord').delay(2500).fadeIn(700, function(){
			spectrum();
		});
		$('.bord').css({borderTopColor: hue, borderLeftColor: hue, borderRightColor: hue, borderBottomColor: hue, color: hue});
	}
	
	//incase there should be an original pattern
	/*var originaldong = ('<p>&#10000;</p>').repeat(20);
	var originalyeahdong = '<div class="row">' + originaldong + '</div>';
	$('.bg').html(originalyeahdong.repeat(30));*/

	//generate the random colours to animate between
	function getColour() {
		var colours = ['rgb(230, 246, 242)','rgb(229, 239, 246)','rgb(247, 238, 250)','rgb(250, 240, 231)','rgb(250, 248, 232)','rgb(244, 250, 232)','rgb(251, 236, 236)'];
		return colours[Math.floor(Math.random() * colours.length)];
	}

	//run through the selected random colours infinitely
	function spectrum(){
		hue = getColour();

		$('.bord').animate({borderTopColor: hue, borderLeftColor: hue, borderRightColor: hue, borderBottomColor: hue, color: hue}, 2000, function(){
			//callback to make it go on forever
			spectrum();
		});
	}

	//generate the webdings. at least one of these is incompatible with IE and phones, which is a shame
	function getDingDong() {
		var dingdong = ['&#9730;', '&#9788;', '&#10014;', '&#10017;', '&#9773;','&#9998;','&#9997;','&#9988;','&#9992;','&#9775;','&#10004;','&#10008;','&#9816;','&#9729;','&#9874;','&#9793;','&#9810;','&#8961;'];
		return dingdong[Math.floor(Math.random() * dingdong.length)];
	}

	$('.container .col a, .close').hover(function(){
		
		if($(this).hasClass('close')) {
			ding = '&#10006;';
		} else {
			ding = getDingDong();
			$(this).find('.icon').html(ding);	
		}

		var dong = ('<p>' + ding + '</p>').repeat(15);
		var yeahdong = '<div class="row">' + dong + '</div>';

		var currentcolour = $('.bord').css('borderTopColor');

		$('.bg').html(yeahdong.repeat(10));
	}, function(){
		$('.bg').empty();
	});

	$('.close').click(function(e){
		$('.video').hide();
		$('.video-inside iframe').remove();
		$('.container').fadeIn(300);
		$('.bg').empty();
		e.preventDefault();
	});

	/*$('.vid').click(function(e){
		var path = $(this)[0].pathname;
		var iframe = '<iframe src="http://player.vimeo.com/video' + path + '?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff&autoplay=true" width="750" height="422" frameborder="0"></iframe>';

		$('.video-inside').html(iframe);

		$('.video').fadeIn(300);
		$('.container').fadeOut(300);
		$('.bg').fadeOut(300, function(){
			$(this).empty().show();
		});
		e.preventDefault();
	});*/

	//initialise and GO GO GO
	init();

});

