$(document).ready(function() {

//Select Box Styling
if (!$.browser.opera) {

        $('select.select').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
                .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
                .after('<span class="select">' + title + '</span>')
                .change(function(){
                    val = $('option:selected',this).text();
                    $(this).next().text(val);
                    })
        });

    };

//Checkbox Styling
	$('input:checkbox').wrap('<span class="checkbox"></span>');
	$('input:checkbox:checked').parent('span.checkbox').addClass('checkbox-select');

	$('span.checkbox').click(function () {
		if($(this).hasClass('checkbox-select')) {
			$(this).removeClass('checkbox-select');
			$(this).children('input').removeAttr("checked");	
		} else {
			$(this).addClass('checkbox-select');
			$(this).children('input').attr("checked", true);
		}		
	});

//FancyBox Lightbox
		
	$("ul.gallery li a").append("<img src='images/magnify.jpg' class='magnify' />");
	$(".magnify").css({"opacity": 0});
	
	$("ul.gallery li a").hover(function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0.77});						
	}, function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0});	
	});
	
//Fade Boxes in randomly

	var count = 0;
	var toShow = new Array();
	var newToShow = new Array();
	var numRand;
	
	$('.item a').each(function(){
		 count++;
		//jquery(this).css({'z-index' :+count+100 });
		$('#logo, #logo a').css({'display' :'block' });
		$(this).addClass('tile-'+count);
		$(this).css({'display' :'none' });
	});
	
	for (var i = 0; i < count; i++) {
		toShow.push(i+1);
	}
	
	showNextImage();

	function showNextImage() {
		numRand = Math.floor(Math.random()*toShow.length);
		
		var show = toShow[numRand];
		
		if (toShow.length > 1) {
			for (var i = 0; i < toShow.length; i++) {
				if (i != numRand) {
					newToShow.push(toShow[i]);
				}
			}
		} else {
			toShow = new Array(numRand);
		}
		
		toShow = newToShow;
		newToShow = new Array();

		$('.tile-'+show).fadeIn(250, function() {
			if (toShow.length > 0) {
				showNextImage();
			}
		});
	}

// image transition
		var maxCount= $('.text-holder > *').length;
		var count=2;
		var previous=1;
		setInterval(imageRotation,3500); //animation speed this is set to 3.5 seconds at the moment
		
function imageRotation() {
		$('#image-'+previous).fadeOut(500); //fade out speed this is set to 0.5 seconds at the moment
		$('#image-'+count).fadeIn(500); //fade in speed this is set to 0.5 seconds at the moment
		previous = count;
		count ++;
		if(count==maxCount+1) {
			count=1;
		}
	};

// image transition
		var maxCount2= $('.text-holder2 > *').length;
		var count2=2;
		var previous2=1;
		setInterval(imageRotation2,3500); //animation speed this is set to 3.5 seconds at the moment
		
function imageRotation2() {
		$('#image-'+previous2).fadeOut(500); //fade out speed this is set to 0.5 seconds at the moment
		$('#image-'+count2).fadeIn(500); //fade in speed this is set to 0.5 seconds at the moment
		previous2 = count2;
		count2 ++;
		if(count2==maxCount2+1) {
			count2=1;
		}
	};




});//end jquery

