/**
 * @author James
 */

/* These lines try to prevent the hidden content from */
/*
var W3CDOM = (document.getElementsByTagName && document.createElement);
if (W3CDOM) document.write('<link rel="stylesheet" href="assets/styles/hides.css" />'); 
*/
jQuery.noConflict();


jQuery(document).ready(function() {
	jQuery('.print').click(function() {window.print(); return false;});
	jQuery('.arrow-link').append(' <img alt=" " src="assets/images/template/generic-small-arrow.gif"/>');
	jQuery('#get-in-touch-header-link').mouseover(function() {
	    jQuery('#get-in-touch-header-link').animate({left:'563px'},140,'swing').animate({left:'551px'},140,'swing').animate({left:'563px'},140,'swing').animate({left:'557px'},140,'swing');
	});
	jQuery('#donate-header-link').mouseover(function() {
	    jQuery('#donate-header-link').animate({left:'773px'},140,'swing').animate({left:'761px'},140,'swing').animate({left:'773px'},140,'swing').animate({left:'767px'},140,'swing');
	});

	if (jQuery('#gallery').length > 0) {
	   jQuery('.picturecontainer').append('<div id="secret-hidden-javascript-picture-title-desc"></div>');
	   jQuery('ul.thumbs li img').click(function(){
	         //Get the picture id
		 var picture_id = jQuery(this).parent().attr('href').match(/[^=]\d*$/)[0];
	         var image_url = jQuery(this).attr('src').replace(/tn_/,'');
	         //create new image attach load event create the dummy element used to calculate the height of the text.
		 var newimage = new Image();
		    
		 jQuery(newimage).load(function() {
		     //Get desciption, if any
		     jQuery.get('http://' + window.location.hostname + '/getsingleimage',{pic_id : picture_id}, function(data) {
			 //fade big imge
			 jQuery('.imageview').animate({opacity: 0},'slow', 'swing', function() {
			     var newimageheight = newimage.height;
			     jQuery(this).animate({height : newimageheight },'slow', 'swing', function() {
				jQuery(this).attr('src',image_url).animate({opacity:1},'slow','swing');	 
			     } )    
			 });
			 //fade title and desciption
			 jQuery('#picture-title-desc').animate({opacity:0},'slow','swing', function() {
			     //alert(jQuery('#secret-hidden-javascript-picture-title-desc').html(data).height());
			     var newtextheight = jQuery('#secret-hidden-javascript-picture-title-desc').html(data).height();
			     jQuery(this).animate({height:newtextheight + 'px', opacity:1},'slow', 'swing').html(data);  
			 })
			 //swap images
			 //swap descriptions 
		     });
		 }).attr('src',image_url);
		return false;
	   });
	}
	if (jQuery('.product').length > 0) {
	    var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 300, // number = milliseconds for onMouseOver polling interval    
		 over: swapDetailsIn, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: function() {} // function = onMouseOut callback (REQUIRED)    
	    };

	    
	   jQuery('.product').hoverIntent(config);
	}
	if(jQuery('#map_container').length > 0) {
	    //Load google maps api
	      google.load("maps", "2", {callback:setUpMap});
   
	}
	
	if(jQuery('#flash-banner').length > 0) {
		 jQuery('#flash-banner').flash({   
			swf: 'home.swf',
			width: '680',
			height: '296'
		});
	}
});

var swapDetailsIn =function(){
	         //Get the product id
		 var product_id = jQuery(this).attr('id').match(/\d*$/)[0];
		 var curr_product_id = jQuery('#merchandise-large-image-container a').attr('id').match(/\d*$/)[0];
		 if (product_id != curr_product_id) {
		     jQuery.get('http://' + window.location.hostname + '/getsingleproduct',{prod_id : product_id}, function(data) {
			 var image_url = data.match(/src="(.*)"/)[1];
			 jQuery(new Image()).load(function() {
			     jQuery('#merchandise-large-image-container').animate({opacity:0},'normal','swing', function() {
				 jQuery(this).html(data).animate({opacity:1},'normal', 'swing');
			     });
			 }).attr('src', image_url);	
		     });
		 }
	   }; 

var setUpMap = function() {
var map = new google.maps.Map2(document.getElementById('map_canvas'));
    map.setCenter(new google.maps.LatLng(50.382692,-4.760256), 13);
    map.addOverlay(new GMarker(new GLatLng(50.384607,-4.747961)));
    map.enableGoogleBar();
    map.addControl(new GSmallZoomControl()); 
    
};


