jQuery.noConflict();
jQuery(document).ready(function($){

// JS-Alert for I7-
if(jQuery.browser.msie && parseInt(jQuery.browser.version)==6){
	alert('Sorry, but your browser is outdated. Please use at least Internet Explorer 7+ or for best view a version of Firefox (e.g. V. 3+).');
}

// Resize background
function resizebg(){
	var topheight = $('div.top').height(),
		headerheight = $('div.header').height(),
		bottomheight = $('div.footer').height(),
		bodyheight = $(document).height(),
		spacerheight = $('div.content').height(),
		heightdif = bodyheight-topheight-headerheight-bottomheight;
	if(heightdif>spacerheight){	$('div.content').css({'min-height':heightdif+'px','height':heightdif+'px'});	}
};
resizebg();

// Initial modalbox
$("a[rel^='modal']").each(function(){
	var target = $(this).attr('href');
	var title = $(target).find('h1:first');
	var width = $(target).width();
	var height = $(target).height();
	
	$(target).dialog({
		'width':width,
		'height':height,
		'bgiframe': true,
		'autoOpen': false,
		'modal': true,
		'title': title,
		'hide':'slide',
		'show':'slide'
	});
	
	$(this).click(function(){
		$(target).dialog('open');
		return false;
	});
});

// Initialize lightbox
$("a[rel^='lightbox']").prettyPhoto({
	opacity: 0.9,
	showTitle: false,
	allowresize: true,
	counter_separator_label: '/'
});

// Hide img & show slideshow
$('div.imgslideshow').each(function(){
	
	var i = $(this);

	i.find('.headerimg').hide();
	i.find('.slideshow').show();
	i.find('.slideshow').height(120);
	i.find('.slideshow #headerslideshow').easySlider({
			'auto':true,
			'pause':7000,
			'continuous':true,
			'nextText':'',
			'prevText':''
	});
	
	i.find('.openbutton').click(function()
	{
		if(!i.hasClass('open'))
		{
			$(this).text('CLICK 4 SMALL VIEW');
			i.addClass('open');
			i.find('.slideshow').animate({'height':'340px'},'slow');
		}else
		{	
			$(this).text('CLICK 4 FULL VIEW');
			i.removeClass('open');
			i.find('.slideshow').animate({'height':'120px'},'slow');
		}
	});
});

//Clear Formfields on Focus
$('input.clearme').each(function(){
	var curval = $(this).val();
	$(this).focus(function(){
		if(curval==$(this).val()){
			$(this).val('');
		}
	});
	$(this).blur(function(){
		if($(this).val()==''){
			$(this).val(curval);
		}
	});
});

// Add first & last class to pagination
$('div.pagination ul li:first').addClass("first");
$('div.pagination ul li:last').addClass("last");

// Initial MP3 Player
$("#jquery_jplayer").each(function(){
	
	$('#player_container').show();
	$(this).show();

	var myPlayList = [
		{id:0,name:"Smooth Sunset",mp3:"tl_files/template/mp3/SmoothSunset.mp3"},
		{id:1,name:"Lookin For S1 To Love",mp3:"tl_files/template/mp3/LookinForSomeoneToLove.mp3"},
		{id:2,name:"Late Nite Trip",mp3:"tl_files/template/mp3/LateNiteTrip.mp3"},
		{id:3,name:"Kontiolahti Chill",mp3:"tl_files/template/mp3/KontiolahtiChill.mp3"},
		{id:4,name:"Bop With Someone New",mp3:"tl_files/template/mp3/BopWithSomeoneNew.mp3"},
		{id:5,name:"The Base",mp3:"tl_files/template/mp3/TheBase.mp3"}
	];
		
	$("#jquery_jplayer").jPlayer({
		ready: function () {
			$('#jpp_counter').text(myPlayList[0]['id']);
			$('#jpp_title').text(myPlayList[0]['name']);
			var track = $(this).setFile(myPlayList[0]['mp3']);
			if($('.jukebox_autostart').length>=1){	track.play(); }
		},
		volume:50
	}).jPlayerId("play", "jpp_play").jPlayerId("pause", "jpp_pause").jPlayerId("stop", "jpp_stop").jPlayerId("loadBar", "jpp_progress_load_bar").jPlayerId("playBar", "jpp_progress_play_bar").onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {}).onSoundComplete( function() { changetrack('next'); });
	
	$('#jpp_next').click(function(){ changetrack('next'); });
	$('#jpp_prev').click(function(){ changetrack('prev'); });
	
	var changetrack = function(direction){
		var count = myPlayList.length-1;
		var cursong = parseInt($('#jpp_counter').text());
		if(direction=='next'){
			if(count>cursong){ var newsong = cursong+1;	}else{ var newsong = 0; }
		}else if(direction=='prev'){
			if(0<cursong){ var newsong = cursong-1;	}else{ var newsong = count; }
		}
		$('#jpp_counter').text(myPlayList[newsong]['id']);
		$('#jpp_title').text(myPlayList[newsong]['name']);
		$("#jquery_jplayer").setFile(myPlayList[newsong]['mp3']).play();
	};
	
	$("#player_container div.buttons div.button").hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
});
	
});
