/*
script.js - Custom script file for Nicola Benedetti
@Date: 22/08/2011
*/

var default_email = '';



$(document).ready(function(){


	// browser version body class
	$('body').addClass(BrowserDetect.browser + ' ' + BrowserDetect.browser + BrowserDetect.version);

		
	// Launch Stratus Soundcloud played plugin	
	$.stratus({
		color: '6A6A6A',
		links: [{ url: 'http://soundcloud.com/nicola-benedetti' }],
		align: 'top'
	});

	// fancy hover animation for archive menu
	$('.archive ul li ul li:not(.open)').hoverIntent( function () {
		$(this).animate({
			"padding-left": '16px'
		}, 200);
	}, function() {
		$(this).animate({
			"padding-left": '0px'
		}, 200);	
	});

	// album slider on music page
	$('#album-slider').serialScroll({
		items:'li',
		prev:'#album-scroller a.prev',
		next:'#album-scroller a.next',
		offset:0, 
		start:0,
		duration:500,
		force:false,
		stop:true,
		lock:false,
		axis:'y',
		cycle:false, //don't pull back once you reach the end
		jump: false //click on the images to scroll to them
	});		

	// work out which is the current album, then go to it's li array index
	var current_id = $('.album-container').attr('id'); // get the current album (post) id
	var li_index = $('#li_' + current_id).index();			
	$('#album-slider').trigger( 'goto', [ li_index ] ); // slide down to it


	// mailing list	
	default_email = $('input#email').val();
	$('.text').click(function() {
		var mail_input = $('.text').val();
		if (mail_input == '' || mail_input == default_email) { 
	    	$('.text').val('');
		}
    });

	$('.text').blur(function() {
		var mail_input = $('.text').val();
		if (mail_input == '') { 
	    	$('.text').val(default_email);
		}			
	});
	
	// add thickbox to images within news content only
	$('.news-open-large p a img').parent().addClass('thickbox');
	
	// style 2nd word in widget title
	var title = $('h3.widgettitle').html();
	var title_array = title.split(' ');
	$('h3.widgettitle').html(title_array[0] + "<span class='bold'> " + title_array[1] + "</span>");
	
});
	
	
function submit_email() {

    var email = $('input#email').val();

	if (email == default_email) {
		show_modal('Please enter a valid email address.');
		exit;
	}

    var ajaxRequest;

    if (window.XMLHttpRequest) {
		ajaxRequest = new XMLHttpRequest();
    } else {
		ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
	}
    
    ajaxRequest.open('POST','wp-content/themes/nicola/subscribe.php',true);	    
    ajaxRequest.onreadystatechange=function() {

		var msg = ajaxRequest.responseText;
		show_modal(msg);
    }
    	   	    
    ajaxRequest.setRequestHeader('Content-type','application/x-www-form-urlencoded');    
    ajaxRequest.send('email=' + email);
	
	return false;

}

function show_modal(msg) {
	$('#ajax-modal').html(msg);
	$('#ajax-modal').dialog({
		height: 160,
		width: 350,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			Okay: function() {
				$( this ).dialog( "close" );
			}
			}
		});	
}


