
	/**
* A simple JavaScript image loaderimage loader
* @author Cuong Tham
* @url http://thecodecentral.com/2008/02/21/a-useful-javascript-image-loader
* @usage
* var loader = new ImageLoader('IMAGE_URL');
* //set event handler
* loader.loadEvent = function(url, image){
*   //action to perform when the image is loaded
*   document.body.appendChild(image);
* }
* loader.load();
*/

//source: http://snipplr.com/view.php?codeview&id=561
// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
  bubbling = bubbling || false;
  if(window.addEventListener)	{ // Standard
    element.addEventListener(type, expression, bubbling);
    return true;
  } else if(window.attachEvent) { // IE
    element.attachEvent('on' + type, expression);
    return true;
  } else return false;
}

var ImageLoader = function(url){
  this.url = url;
  this.image = null;
  this.loadEvent = null;
};

ImageLoader.prototype = {
  load:function(){
    this.image = document.createElement('img');
    var url = this.url;
    var image = this.image;
    var loadEvent = this.loadEvent;
    addListener(this.image, 'load', function(e){
      if(loadEvent != null){
        loadEvent(url, image);
      }
    }, false);
    this.image.src = this.url;
  },
  getImage:function(){
    return this.image;
  }
};

// remap jQuery to $
(function($){})(window.jQuery);


/* trigger when page is ready */
$(document).ready(function (){

	// your functions go here
	try{
	$('a[rel=group]').fancybox({
		'padding':0
	});
	}
	catch(e){
		//not the right page
	}
	try{
		$('#fb-feed').soSoSocial();
	}
	catch(e){
		//llllllllllllzzzzzyyyyyyy
	}

	if($('body').hasClass('home')){
		var loadcount =0;
		for(var i=0;i<slideshow.length;i++){
			var heavyImage = new Image(); 
			heavyImage.onload = function(){
				loadcount++;
				if(loadcount == slideshow.length){
					var derp = setTimeout("slide();",5000);
				}
			}
			heavyImage.src = slideshow[i];
		}
		
	}

});

var count = 0;

function slide(){ 
	if(count >= slideshow.length){
		count = 0;
	}
	//var slideid = 'slide'+Math.Rand
	$('#show-load img').attr('src' , slideshow[count]);
	
	// var heavyImage = new Image(); 
	// heavyImage.onload = function(){
		
	// }
	// heavyImage.src = slideshow[count];
	$('#head-slideshow').fadeOut('slow',function(){
			$('#head-slideshow img').attr('src', slideshow[count]); 
			$('#head-slideshow').show();
			//$('.header-image img').attr('style','');
			//$('#newimage').attr('id','');
			count++;
			var derp = setTimeout("slide();",5000);
	});
	
	
	

}

$('#mc_mv_EMAIL').bind('focus', function(){
	if ($(this).attr('value') == 'Email Address'){
					$(this).attr('value' , '')
				}
})

$('#mc_mv_EMAIL').bind('blur', function(){
	if ($(this).attr('value') == ''){
					$(this).attr('value' , 'Email Address')
				}
})

$('#mc_mv_FNAME').bind('focus', function(){
	if ($(this).attr('value') == 'First Name'){
					$(this).attr('value' , '')
				}
})

$('#mc_mv_FNAME').bind('blur', function(){
	if ($(this).attr('value') == ''){
					$(this).attr('value' , 'First Name')
				}
})

$('#mc_mv_PHONE-detail1').bind('focus', function(){
	if ($(this).attr('value') == 'Phone'){
					$(this).attr('value' , '')
				}
})

$('#mc_mv_PHONE-detail1').bind('blur', function(){
	if ($(this).attr('value') == ''){
					$(this).attr('value' , 'Phone')
				}
})

/*
<input id="searchinput" type="text" onfocus="if (jQuery(this).attr('value') == 'search the thousands directory'){
					jQuery(this).attr('value' , '')
				}" onblur="if (jQuery(this).attr('value') == ''){
					jQuery(this).attr('value' , 'search the thousands directory')
				}" onkeypress="
					var key = event.keyCode || event.which;
					if(key == 13){
						window.location.href = 'http://thethousands.com.au/melbourne/?s='+this.value;
					}
				" value="search the thousands directory">


*/

/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/
	$('#menu-item-78, #contact-id').click(function(e){
		e.preventDefault();
		var path = 'http://'+window.location.host;
		if(window.location.host == 'localhost'){
			path +='/riva';
		}
		var data = {
			action: 'ajaxcall',
			mail: true
		};
		jQuery.post(path+'/wp-admin/admin-ajax.php', data, function(response) {
			$('#ajax-mail').empty();

			$('#ajax-mail').html('<div id="mail-overlay"></div>'+response);
			$('#mail-overlay').css({
				'height':$(document).height()+'px',
				'width':$(window).width()+'px'
			})
			$('#ajax-mail #mailchimp').css({
				'top':$(window).height()/2-150+'px'
			})
			$('#mc_mv_EMAIL').bind('focus', function(){
				if ($(this).attr('value') == 'Email Address'){
								$(this).attr('value' , '')
							}
			})

			$('#mc_mv_EMAIL').bind('blur', function(){
				if ($(this).attr('value') == ''){
								$(this).attr('value' , 'Email Address')
							}
			})

			$('#mc_mv_FNAME').bind('focus', function(){
				if ($(this).attr('value') == 'First Name'){
								$(this).attr('value' , '')
							}
			})

			$('#mc_mv_FNAME').bind('blur', function(){
				if ($(this).attr('value') == ''){
								$(this).attr('value' , 'First Name')
							}
			})

			$('#mc_mv_PHONE-detail1').bind('focus', function(){
				if ($(this).attr('value') == 'Phone'){
								$(this).attr('value' , '')
							}
			})

			$('#mc_mv_PHONE-detail1').bind('blur', function(){
				if ($(this).attr('value') == ''){
								$(this).attr('value' , 'Phone')
							}
			})
		})
	});

	$(window).resize(function(e){
		$('#mail-overlay').css({
				'height':$(document).height()+'px',
				'width':$(window).width()+'px'
		})
		$('#ajax-mail #mailchimp').css({
			'top':$(window).height()/2-150+'px'
		})
	});



	$('#mail-overlay').live('click',function(e){
		$(this).parent().contents().remove();
	})

	$('#refresh-stream, #stream-head').live('click', function(e){
		e.preventDefault();
		var path = 'http://'+window.location.host;
		if(window.location.host == 'localhost'){
			path +='/riva';
		}
		var data = {
			action: 'ajaxcall',
			stream: true
		};
		jQuery.post(path+'/wp-admin/admin-ajax.php', data, function(response) {
			$('#ajax-stream').empty();
			$('#ajax-stream').append(response);
			
			
		})
	});

	$('#next, #prev').live('click', function(e){
		e.preventDefault();
		var path = 'http://'+window.location.host;
		if(window.location.host == 'localhost'){
			path +='/riva';
		}


		var offset = parseInt($(this).attr('data-offset'));
		var id = $(this).attr('data-id');
		var data = {
			action: 'ajaxcall',
			gallery: true,
			offset: offset,
			id: id
		};
		jQuery.post(path+'/wp-admin/admin-ajax.php', data, function(response) {
			$('#ajax-gallery').empty();
			$('#ajax-gallery').html(response);
			$('#ajax-gallery a[rel=group]').fancybox({
				'padding':0
			});
			
		})
		//e.preventDefault();
	});


