/*
Bones Scripts File
Author: Eddie Machado

This file should contain any js scripts you want to add to the site.
Instead of calling it in the header or throwing it inside wp-head()
this file will be called automatically in the footer so as not to 
slow the page load.

*/

/* imgsizer (flexible images for fluid sites) */
var imgSizer={Config:{imgCache:[],spacer:"/path/to/your/spacer.gif"},collate:function(aScope){var isOldIE=(document.all&&!window.opera&&!window.XDomainRequest)?1:0;if(isOldIE&&document.getElementsByTagName){var c=imgSizer;var imgCache=c.Config.imgCache;var images=(aScope&&aScope.length)?aScope:document.getElementsByTagName("img");for(var i=0;i<images.length;i++){images[i].origWidth=images[i].offsetWidth;images[i].origHeight=images[i].offsetHeight;imgCache.push(images[i]);c.ieAlpha(images[i]);images[i].style.width="100%";}
if(imgCache.length){c.resize(function(){for(var i=0;i<imgCache.length;i++){var ratio=(imgCache[i].offsetWidth/imgCache[i].origWidth);imgCache[i].style.height=(imgCache[i].origHeight*ratio)+"px";}});}}},ieAlpha:function(img){var c=imgSizer;if(img.oldSrc){img.src=img.oldSrc;}
var src=img.src;img.style.width=img.offsetWidth+"px";img.style.height=img.offsetHeight+"px";img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"
img.oldSrc=src;img.src=c.Config.spacer;},resize:function(func){var oldonresize=window.onresize;if(typeof window.onresize!='function'){window.onresize=func;}else{window.onresize=function(){if(oldonresize){oldonresize();}
func();}}}}

// as the page loads, cal these scripts
jQuery(document).ready(function() {
	
	// add all your scripts here
	// Remove menu links
	// jQuery('nav[role="navigation"] .menu ul li:nth-child(2) a').addClass("no-link");
	// jQuery('nav[role="navigation"] .menu ul li:nth-child(2) a').attr("href", "#");
	jQuery('nav[role="navigation"] .menu ul li:nth-child(4) a').addClass("no-link");
	jQuery('nav[role="navigation"] .menu ul li:nth-child(4) a').attr("href", "#");
	// jQuery('nav[role="navigation"] .menu ul li:nth-child(6) a').addClass("no-link");
	// jQuery('nav[role="navigation"] .menu ul li:nth-child(6) a').attr("href", "#");

	// jQuery('.footer-links ul li:nth-child(2) a').addClass("no-link");
	// jQuery('.footer-links ul li:nth-child(2) a').attr("href", "#");
	jQuery('.footer-links ul li:nth-child(4) a').addClass("no-link");
	jQuery('.footer-links ul li:nth-child(4) a').attr("href", "#");
	// jQuery('.footer-links ul li:nth-child(6) a').addClass("no-link");
	// jQuery('.footer-links ul li:nth-child(6) a').attr("href", "#");
	// END Remove menu links
	
	// Social icons //////////////
	jQuery(".header-top-current-social-title").hide();
	
	jQuery("#header-top a").mouseenter(function() {
		var pos = jQuery(this).offset();
		var width = jQuery(this).width();
		var height = jQuery(this).height();
		jQuery(".header-top-current-social-title").css( { "left": (pos.left - 15) + "px", "bottom":pos.top-39 + "px" } );
		
		var index = jQuery(this).index();
		console.log(index);
		switch (index) {
			case 0:
			    jQuery(".header-top-current-social-title").html('Facebook');
			    break;
			case 1:
			    jQuery(".header-top-current-social-title").html('Twitter');
			    break;
			case 2:
			    jQuery(".header-top-current-social-title").html('YouTube');
			    break;
			case 3:
			    jQuery(".header-top-current-social-title").html('Flickr');
			    break;			
			case 4:
				jQuery(".header-top-current-social-title").html('Myspace');
				break;
			case 5:
				jQuery(".header-top-current-social-title").html('Last.fm');
				break;
			case 6:
				jQuery(".header-top-current-social-title").html('Feed');
				break;
		}
		
		jQuery(".header-top-current-social-title").show();
	});

	jQuery("#header-top img").mouseleave(function() {
		jQuery(".header-top-current-social-title").hide();
	});
	// END Social icons	//////////////
	
	
	// Custom Event post type //////////////
	jQuery('#upload_image_button').click(function() {
	 window.send_to_editor = function(html) {
	 	imgurl = jQuery('img',html).attr('src');
	 	jQuery('#upload_image').val(imgurl);
	 	tb_remove();
	}
	 tb_show('', 'media-upload.php?post_id=1&amp;type=image&amp;TB_iframe=true');
	 return false;
	});

	jQuery('#upload_image_button2').click(function() {
	 window.send_to_editor = function(html) {
	 imgurl = jQuery('img',html).attr('src');
	 jQuery('#upload_image2').val(imgurl);
	 tb_remove();
	}
	 tb_show('', 'media-upload.php?post_id=1&amp;type=image&amp;TB_iframe=true');
	 return false;
	});
	// END Custom Event post type //////////////
	
	
	// Image Hover TODO //////////////
	jQuery(function() {
	   jQuery("img.over")
	        .mouseover(function() {
				var src0 = jQuery(this).attr("src");
	            // var src = jQuery(this).attr("src").match(/[^\.]+/) + "-over.png";
				var src = jQuery(this).attr("src").replace('.png', '-over.png');
				
	            jQuery(this).attr("src", src);
	        })
	        .mouseout(function() {
	            var src = jQuery(this).attr("src").replace("-over", "");
	            jQuery(this).attr("src", src);
	        });
	});
	// END Image Hover //////////////
	
	
	// Comments
	jQuery('#respond').hide();
	jQuery('#comments-do-comment').click(function() {

	  jQuery('#respond').slideToggle('fast', function() {
	    // Animation complete.
	  });
	});
	// END Comments
	
	// Facebook box
	// jQuery('.like-box').css('color', '#696969');
	// END Facebook box
	
	// Hover feed-archive
	jQuery('.sidebar #feeds .feed-archive ul li').hover(
		
	     function() {  // mouseover
	          jQuery(this).append('<span class="arrow">&nbsp;&nbsp;&larr;</span>'); 
	     }, 
	     function() {  // mouseout 
	          jQuery(this).find('span.arrow').remove(); 
	     } 
	);
	// END Hover feed-archive
	
	
	// Agenda
	// jQuery("#events-table table tr:even").hide();
	// jQuery("#events-table table tr:first-child").show();
	jQuery("#events-table table tr td.event-amplificasom-info .more-info").hide();
	
	// jQuery("#events-table table tr:odd").click(function(){
	// 	var index = jQuery(this).index();
	// 	var index_plus = parseInt(index) + 1;
		
	// 	jQuery("#events-table table tr:eq("+index_plus+")").slideToggle('fast');
	// });
	
	jQuery("#events-table table tr").hover(
		function(){
			jQuery(this).find("td.event-amplificasom-info .more-info").show();
		},
		function(){
			jQuery(this).find("td.event-amplificasom-info .more-info").hide();
		}
	);	
	// END Agenda


	// Avails
	jQuery("#bands-table table tr:even").hide();
	jQuery("#bands-table table tr:first-child").show();
	jQuery("#bands-table table tr td.band-amplificasom-info .more-info").hide();
	
	jQuery("#bands-table table tr:odd").click(function(){
		var index = jQuery(this).index();
		var index_plus = parseInt(index) + 1;
		
		jQuery("#bands-table table tr:eq("+index_plus+")").slideToggle('fast');
	});
	
	jQuery("#bands-table table tr:odd").hover(
		function(){
			jQuery(this).find("td.band-amplificasom-info .more-info").show();
		},
		function(){
			jQuery(this).find("td.band-amplificasom-info .more-info").hide();
		}
	);	
	// END Avails
	
	

	

	jQuery.fn.preload = function() {
	    this.each(function(){
	        jQuery('<img/>')[0].src = this;
	    });
	}	
	
 
}); /* end of as page load scripts */

