
var addthis_config = {"data_track_clickback":true};

$(document).ready(function()
{
	$("a.isFeaturedImage").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	300, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			//return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			var img = ''+currentArray[currentIndex];
			var id = img.substring(img.lastIndexOf('/')+1);
			id = id.substr(0, id.indexOf('-'));
			return $('#fi-'+id).html().replace(/\&amp;quot;/g, '"');
		}
	});
	
	$('a._blank').bind('click', function(event) {
		event.preventDefault();
		window.open($(this).attr('href'));
	});

	// addthis social networking
	var addThis = $('<div class="addthis_toolbox addthis_32x32_style addthis_default_style"><div id="lAddThis"><a class="addthis_button_rss_follow" addthis:url="http://www.mjfmultimedia.com.au/feed.xml"></a><a class="addthis_button_facebook_follow" addthis:userid="mjfmultimedia"></a><a class="addthis_button_twitter_follow" addthis:userid="MJFMultimedia"></a><a class="addthis_button_linkedin_follow" addthis:userid="martyfriedel"></a><a class="addthis_button_email"></a></div><a class="addthis_button_facebook_like" fb:like:href="http://www.facebook.com/mjfmultimedia" fb:like:layout="standard" fb:like:show_faces="false" fb:like:width="264" fb:like:height="30" fb:like:colorscheme="dark" fb:like:font="arial"></a></div>');
	$('#lSocialPlacement').append(addThis);

	// timer
	var time = 11; // time in seconds
	
	var features = $('#lFeature>div.lWrapper>ul');
	var toShow = features.children('li').length;
	var nowShow = 1;
	var nextShow = 0;
	
	if (toShow > 1)
	{
		// build 'control' buttons
		var controls = $('<ol></ol>');
		for (var i = 0; i < toShow; i++)
		{
			var li = $('<li></li>');
			li.attr('id', 'feature-control-'+(i+1));
			li.css('cursor', 'pointer');
			li.bind('click', function() {
				potentialNextShow = $(this).attr('id').substring(16);
				if (potentialNextShow != nowShow)
				{
					nextShow = potentialNextShow;
					changeFeature();
					clearInterval(interval);
				}
			});
			controls.append(li);
		}
		controls.children('li:first-child').addClass('current');
		$('#lFeature>div.lWrapper').append(controls);
		
		// process feature function
		// increments to the "next" slide
		function processFeature()
		{
			nextShow = nowShow + 1;
			if (nextShow > toShow)
			{
				nextShow = 1;
			}
			
			changeFeature();
		}
		
		// change feature function
		// actually does the fade in/fade out
		function changeFeature()
		{
			if (nextShow > 0)
			{
				features.children('li:nth-child('+nowShow+')').fadeOut();
				features.children('li:nth-child('+nextShow+')').fadeIn();
				
				controls.children('li').removeClass('current');
				controls.children('li:nth-child('+nextShow+')').addClass('current');
				
				nowShow = nextShow;
				nextShow = 0;
			}
		}
		
		var interval = window.setInterval(processFeature, time * 1000);
	}

});





var mc_custom_error_style = '';
var fnames = new Array();var ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';
var head= document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://downloads.mailchimp.com/js/jquery.form-n-validate.js';
head.appendChild(script);
var err_style = '';
setTimeout('mce_preload_check();', 250);

var mce_preload_checks = 0;
function mce_preload_check(){
    if (mce_preload_checks>40) return;
    mce_preload_checks++;
    try {
        var jqueryLoaded=jQuery;
    } catch(err) {
        setTimeout('mce_preload_check();', 250);
        return;
    }
    try {
        var validatorLoaded=jQuery("#fake-form").validate({});
    } catch(err) {
        setTimeout('mce_preload_check();', 250);
        return;
    }
    mce_init_form();
}
function mce_init_form(){
    jQuery(document).ready( function($) {
      var options = { errorClass: 'mce_inline_error', errorElement: 'div', onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
      var mce_validator = $("#mc-embedded-subscribe-form").validate(options);
      $("#mc-embedded-subscribe-form").unbind('submit');//remove the validator so we can get into beforeSubmit on the ajaxform, which then calls the validator
      options = { url: 'http://mjfmultimedia.us1.list-manage1.com/subscribe/post-json?u=b52b601f1403bf1afda9a9c1e&id=d6f73b9841&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                    beforeSubmit: function(){
                        $('#mce_tmp_error_msg').remove();
                        $('.datefield','#mc_embed_signup').each(
                            function(){
                                var txt = 'filled';
                                var fields = new Array();
                                var i = 0;
                                $(':text', this).each(
                                    function(){
                                        fields[i] = this;
                                        i++;
                                    });
                                $(':hidden', this).each(
                                    function(){
                                        if (fields.length == 2) fields[2] = {'value':1970};//trick birthdays into having years
                                    	if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                    		this.value = '';
									    } else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                    		this.value = '';
									    } else {
	                                        this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
	                                    }
                                    });
                            });
                        return mce_validator.form();
                    }, 
                    success: mce_success_cb
                };
      $('#mc-embedded-subscribe-form').ajaxForm(options);      
      
    });
}
function mce_success_cb(resp){
    $('#mce-success-response').hide();
    $('#mce-error-response').hide();
    if (resp.result=="success"){
		
		$('#mc-embedded-subscribe-form').slideUp();
		
        $('#mce-'+resp.result+'-response').html(resp.msg);
        $('#mce-'+resp.result+'-response').slideDown();
        $('#mc-embedded-subscribe-form').each(function(){
            this.reset();
    	});
    } else {
        var index = -1;
        var msg;
        try {
            var parts = resp.msg.split(' - ',2);
            if (parts[1]==undefined){
                msg = resp.msg;
            } else {
                i = parseInt(parts[0]);
                if (i.toString() == parts[0]){
                    index = parts[0];
                    msg = parts[1];
                } else {
                    index = -1;
                    msg = resp.msg;
                }
            }
        } catch(e){
            index = -1;
            msg = resp.msg;
        }
        try{
            if (index== -1){
                $('#mce-'+resp.result+'-response').html(msg);   
                $('#mce-'+resp.result+'-response').slideDown();         
            } else {
                err_id = 'mce_tmp_error_msg';
                html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
                
                var input_id = '#mc_embed_signup';
                var f = $(input_id);
                if (ftypes[index]=='address'){
                    input_id = '#mce-'+fnames[index]+'-addr1';
                    f = $(input_id).parent().parent().get(0);
                } else if (ftypes[index]=='date'){
                    input_id = '#mce-'+fnames[index]+'-month';
                    f = $(input_id).parent().parent().get(0);
                } else {
                    input_id = '#mce-'+fnames[index];
                    f = $().parent(input_id).get(0);
                }
                if (f){
                    $(f).append(html);
                    $(input_id).focus();
                } else {
                    $('#mce-'+resp.result+'-response').html(msg);
                    $('#mce-'+resp.result+'-response').slideDown();
                }
            }
        } catch(e){
            $('#mce-'+resp.result+'-response').html(msg);
            $('#mce-'+resp.result+'-response').slideDown();
        }
    }
}
