﻿var _DEBUG = false;
var logoCycleTime = 2.;  //hours
var randShinseki = true;

$(window).ready(function() {

    if(_DEBUG) $('#menutemp').draggable().css('display','');
    
    noEventsCheck();
    ieFont();
    
    selectLogo();
    setupSliders();
        
    filterA();
    
    eventCols();
    
    //lovColors();
    //copyr();
    //fixShinsekiOvers();
});
function noEventsCheck(){
    if($('.noevents').length>0) document.location.href='./?past=1';
}

function eventCols(){
    var min=200, marg=50;
    $('.ddj').each(function(){
        var dj = $('.dj',this), dt = $('.details',this);
        var m = dj.outerHeight()>dt.outerHeight()?dj.outerHeight():dt.outerHeight();
        if(m+marg>min) $(this).height(m+marg);
    });
}

function ieFont(){
    if($.browser.msie){
        $('.ename,.edate,.ename a').css('font-size','35px').css('letter-spacing','2px').css('font-weight','bold').css('margin-bottom','7px');
        $('.shinCapOver').css('letter-spacing','2px').css('font-weight','bold');
    }
}

function fixShinsekiOvers(){
    $('.shinCapOver').each(function(){
        var delta = $(this).height()-53;
        if(delta<55)delta=0;
        $(this).next().css('margin-top', function(index,value) {
          return (parseInt(value.replace('px','')) - delta)+'px';
        });
    });

}

function filterA(){
    var k = '_sites/chasewolf/';
    $("a[href*='"+k+"']").each( function() { $(this).attr('href', $(this).attr('href').replace(k,'') ); });
}

function selectLogo(f){
    var k='lg', c='';
    if($.cookie(k)!=null&&!f){
        c=$.cookie(k);
    } else{
        c = Math.floor(Math.random()*___NL+1);
        et = '\''+parseFloat(logoCycleTime/24)+'\'';
        $.cookie(k, c, {expires: et });
    }
    var p = '/inc/nu/img/logo/'+formatNum(c,3)+'.jpg';
    $('#logo').css('background','url('+p+')');
    // * TODO:: For footer as well
}

var friCols = [];
function lovColors(){
    $('#lovers .r a, #lovers .l a').hover(function() {
        var key = $(this).text();
        var col = friCols[key];
        if(col==null){
         col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'; 
         friCols[key]=col; 
        }
        $(this).animate({borderBottomColor:col}, 100);
    },function(){
        $(this).animate({borderBottomColor: "#ffffff"}, 200);
    });
}


function setupSliders(){
    if(randShinseki){$('#shinseki ul').randomize('li');}    
    
    $('div.slider li').each(function(){ // need to dynamically set the width and height
        $(this).width( $(this).parent().parent().width() );
        $(this).height( $(this).parent().parent().height() );
    });
    
    $('div.slider').each(function(){
    
        $(this).easySlider({
	        auto: true, 
	        continuous: true,
	        numeric:false,
		    prevText:'<img src="/inc/nu/img/sl-prev.jpg" width="20" height="20">',
		    nextText:'<img src="/inc/nu/img/sl-next.jpg" width="20" height="20">',
	        speed:100,
	        pause:15000
        });
        
    });
	$("#shinseki").easySlider({
		auto: true, 
		continuous: true,
		numeric:false,
		prevText:'<img src="/inc/nu/img/sl-prev.jpg" width="20" height="20">',
		nextText:'<img src="/inc/nu/img/sl-next.jpg" width="20" height="20">',
		speed:300,
		pause:8000
	});
}

function copyr(){
    var c = 'CHASEWOLF', d = '(C) ALL PHOTOS <b>'+new Date().getFullYear().toString()+'</b>', n=4, chances=5, str='';
    for(i=0;i<n;i++){
        if(Math.floor(Math.random()*chances)==1){str+=d;}else{str+=c;}
        str+=' ';
    }
    $('#footer .copyr').html(str);
}
function formatNum(n, len) {
    var r = "" + n;
    while (r.length < len) {
        r = "0" + r;
    }
    return r;
}
