var $j = jQuery.noConflict();


var	downstart=0;	
var menu=1;
var ht=$j(window).height()
var wdth=$j(window).width()
var new_width = '';
var new_height = '';
var pathname = window.location.pathname;
	
$j(function() {
	$j('#load').show();
	
	checkStyleSize();
	
	$j(window).resize(function() {
		checkStyleSize();
	});

	$j('#wrapper').delay(3000).css({'visibility':'visible'});
	$j("#header").delay(100).fadeOut(3000);
	
    //when entering the header area show the menu
	$j("#headerwrapper").mouseenter(function() {
		 if ($j('#header').is(':visible')) {
		 	
		 }//if menu is already down or going up kill that process
		 else{
		 	$j('#header').stop(); 	
			$j('#header').fadeIn(1000);
		 }
	 });
	 
	 //on leaving the menu area
	 $j("#headerwrapper").mouseleave(function() {
		 if ($j('#menu').is(':visible')) {
		 	$j("#header").delay(3000).fadeOut(1000);		 	
		 }
	 });

	$j("a.fancybox").fancybox({
		'overlayShow'		: true,
		'overlayOpacity'	: 1,
		'overlayColor'		: '#000',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'outside',
		'scrolling'			: 'no',
		'centerOnScroll'	: true,
		'cyclic'			: true,
		'autoScale'			: true,
		'onComplete': function () { $j("body").css("overflow", "hidden"); },
		'onClosed': function() { $j("body").css("overflow", "auto"); }, 
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

	$j(".various").fancybox({
		maxWidth	: 800,
		maxHeight	: 600,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
		
});



$j(window).bind("load", function() { 
  $j('#load').fadeOut(600);
  checkStyleSize();
});

$j(document).ready(function() {
  checkStyleSize();	
});

function checkStyleSize(){
	
	wdth=$j(window).width()
	ht=$j(window).height()
	
	//660/580
	width=ht*1.14;
	height=wdth/1.14;

	if(height<890 || width<1035){
		if(width>wdth){new_width=wdth;}else{new_width=width;}
		if(height>ht){new_height=ht;}else{new_height=height;}

		if(550<new_height){
		}else{
			$j('#body').css({'top': '0px'});
			height=new_height=ht;
			width=new_width=ht*1.14;
		}	
	}
	else{
		$j('#body').css({'top': '10px'});
		new_height=890;
		new_width=1035;
	}

	if(stristr(pathname, '/news/')){
		var columnW = 260;
	    var primaryW = (Math.floor( (winsize=$j(window).width()) / columnW ) * columnW)-columnW;
	    margin=((winsize-primaryW)/2)-5;
	    $j('#blogpost_wrapper').css({'left': margin+2.5});
	    $j('#blogpost_wrapper').css('width', primaryW+20);
	    $j('#blogpost_wrapper').css('width', primaryW+20);
	    width=primaryW-15;
	    if(width<570){
	    	width=570;	
	    }
	    //width=new_width-30;
    }
	else if(pathname=='/miscellanea/'){
		var columnW = 260;
	    var primaryW = (Math.floor( (winsize=$j(window).width()) / columnW ) * columnW)-columnW;
	    margin=((winsize-primaryW)/2);
	    $j('#blogposters #blogpost_wrapper').css({'left': margin+2.5});
	    $j('#blogposters #blogpost_wrapper').css('width', primaryW+20);
	    $j('#blogposters #blogpost_wrapper').css('width', primaryW+20);
	    width=primaryW-10;
	    if(width<570){
	    	width=570;	
	    }
	}
	else{
		width=new_width-30;		
	}
	
	
	$j('#wrapper').css({'max-height':(new_height-20), 'width':(width)}); 
	$j('#headerwrapper').css({'width':(width)});
	$j('#hidden_menu').css({'width':(width)});

	$j('#load_logo').css({'height':(new_height-15)});

	if(pathname=='/'){
		$j('.home #gallery').css({'margin-top':-10,'height':(new_height-90)});
		$j('.home #gallery img').css({'height':(new_height-80)});
	}
	
	$j('#footer').css({'width':((new_width)-50)});	


	$j('#submenu').css({ 'right': ((wdth-(new_width)+30) )/2 });	
}	




function stristr (haystack, needle, bool) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfxied by: Onno Marsman
    // *     example 1: stristr('Kevin van Zonneveld', 'Van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: stristr('Kevin van Zonneveld', 'VAN', true);
    // *     returns 2: 'Kevin '
    var pos = 0;

    haystack += '';
    pos = haystack.toLowerCase().indexOf((needle + '').toLowerCase());
    if (pos == -1) {
        return false;
    } else {
        if (bool) {
            return haystack.substr(0, pos);
        } else {
            return haystack.slice(pos);
        }
    }
}
