$(document).ready(function(){
	var frames = [];
	for (i = 0; i < $('.frame').size(); i++){
		frames[i] = [];
		for(b = 0; b < 2; b++){
			frames[i][b] = i + b;	
		}
	}
	var counter=0;
	$('.frame').each(function(index) {
		frames[counter][0]=$(this).children('.image').html();
		frames[counter][1]=$(this).children('.content').html();
		counter++;
  	});
	$('#imageframe').html(frames[frames.length-1][0]);
	$('#jquerycontent').html(frames[frames.length-1][1]);
	counter=-1;
	var targetframe = 0;
	$('#imageframe').everyTime(6000, function() {
    	if(counter < $('.frame').size() - 1){
			counter++;
		}
		else{
			counter=0;	
		}
		if(targetframe==0){
			$('#imageframetwo').fadeOut(500);
			$('#jquerycontenttwo').fadeOut(500);
			$('#imageframe').html(frames[counter][0]);
			$('#jquerycontent').html(frames[counter][1]);
			$('#imageframe').fadeIn(500);
			$('#jquerycontent').fadeIn(500);
			targetframe=1;
		}
		else{
			$('#imageframe').fadeOut(500);
			$('#jquerycontent').fadeOut(500);
			$('#imageframetwo').html(frames[counter][0]);
			$('#jquerycontenttwo').html(frames[counter][1]);
			$('#imageframetwo').fadeIn(500);
			$('#jquerycontenttwo').fadeIn(500);
			targetframe=0;
		}
	});

	$("ul.topnav li a").click(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
});
