(function($){
    //Resize image on ready or resize
    $.fn.supersize = function(size) {  

        //Invoke the resizenow() function on document ready
        $(document).ready(function() {
            $('#slideContainer').resizenow(size);
        });
        //Invoke the resizenow() function on browser resize
        $(window).bind("resize", function() {
            $('#slideContainer').resizenow(size);
        });
    };
    //Adjust image size
    $.fn.resizenow = function(size) {
        //Define starting width and height values for the original image
		  
        var startwidth = size[0];  
        var startheight = size[1];
        //Define image ratio
        var ratio = startheight/startwidth;
        //Gather browser dimensions
        var browserwidth = $(window).width();
        var browserheight = $(window).height();
        //Resize image to proper ratio
        if ((browserheight/browserwidth) > ratio) {
            $(this).height(browserheight);
            $(this).width(browserheight / ratio);
            $(this).children().height(browserheight);
            $(this).children().width(browserheight / ratio);
        } else {
            $(this).width(browserwidth);
            $(this).height(browserwidth * ratio);
            $(this).children().width(browserwidth);
            $(this).children().height(browserwidth * ratio);
        }
        //Make sure the image stays center in the window
        $(this).children().css('left', (browserwidth - $(this).width())/2);
        $(this).children().css('top', (browserheight - $(this).height())/2);
    };
})(jQuery);


$(document).ready(function() {

$('#darkBg').animate({opacity: 0, height: '35' },0);
$('.contact').animate({height: '20' },0).addClass('closed');


$('.contact a').click(function(e){
	e.stopPropagation();
});

$('.contact').click(function(){

	if ($(this).hasClass('closed')){
		$('#darkBg').animate({height: '200', opacity: 0.5 },400);
		$('.contact').animate({height: '180' },400).removeClass('closed').addClass('open');
	} else {
		$('#darkBg').animate({height: '35', opacity: 0 },400);
		$('.contact').animate({height: '20' },400).removeClass('open').addClass('closed');
	}
	
});

	var sWidth = $(window).width();
	var dims = new Array();
	var size;

	if (sWidth > 900){
		size = 'medium/';
		dims[0] = '1400';
		dims[1] = '900';
		
			if (sWidth > 1400){
				size = 'large/';
				dims[0] = '2560';
				dims[1] = '1417';
			}
	} else {
		size = 'small/';
		dims[0] = '960';
		dims[1] = '660';
	}
	

    $("div#slideContainer").supersize(dims);

	
	var images = new Array( 'bia.jpg', 'casio.jpg', 'ccc2.jpg', 'daikin.jpg', 'dunlop1.jpg', 'dunlop2.jpg', 'harley1.jpg', 'harley2.jpg',	'harley3.jpg', 'lotus.jpg', 'samheath.jpg', 'samheath2.jpg'	);
	//var showDark = new Array('0.1','0.1','0.1','0.0','0.1','0.1','0.1','0.0','0.0','0.1','0.1','0.1','0.1','0.1');
	
		
		// detect size and pick appropriate images
		
		var dir = '/a/img/';
		var c = '0';
		var elClass = '';
		
		while (c < images.length){
			//elClass = ' class="op_'+showDark[c]+'"';
			out = '<img src="'+dir+size+images[c]+'"'+elClass+'>';
			c++;
			$('#slideContainer').append(out);
		}
		
		$('.copyArea, .leftButton, .rightButton').animate({
			opacity: 1
		}, 0);
		
		$('.contactLogo').animate({
			opacity: 0.9
		},0);
		

    $('#slideContainer').cycle({
        prev:   '.rightButton',
        next:   '.leftButton',
		  speed: 1000,
		  timeout: 0,
		  sync: 1,
		  slideResize: 0,
		  random: 1
    });  
	 
});
