/*
 * Image Centering
 * Copyright 2009 Drew Wilson
 * www.drewwilson.com
 *
 * Version 1.0   -   Updated: Oct. 10, 2009
 *
 * This Plug-In will center images inside of it's parent element.
 * By default it even scales each image up or down to fit inside it's parent element.
 * It will also wait to make sure each image is loaded before doing any re-sizing.
 *
 * This Image Centering jQuery plug-in is dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($){$.fn.imgCenter=function(options){var defaults={parentSteps:0,scaleToFit:true,centerVertical:true,complete:function(){},start:function(){},end:function(){}};var opts=$.extend(defaults,options);opts.start.call(this);var len=this.length-1;return this.each(function(i){var current=i;var org_image=$(this);org_image.hide();var theParent=org_image;for(var i=0;i<=opts.parentSteps;i++){theParent=theParent.parent();}
var parWidth=parseInt(theParent.width());var parHeight=parseInt(theParent.height());var parAspect=parWidth/parHeight;if(org_image[0].complete){imgMath(org_image);}else{var loadWatch=setInterval(watch,500);}
function watch(){if(org_image[0].complete){clearInterval(loadWatch);imgMath(org_image);}}
function imgMath(org_image){var imgWidth=parseInt(org_image.width());var imgHeight=parseInt(org_image.height());var imgAspect=imgWidth/imgHeight;if(parWidth!=imgWidth||parHeight!=imgHeight){theParent.css("overflow","hidden");if(opts.scaleToFit){if(parAspect>=1){org_image.css({"width":parWidth+"px"});imgWidth=parWidth;imgHeight=Math.round(imgWidth/imgAspect);if((parWidth/imgAspect)<parHeight){org_image.css({"height":parHeight+"px","width":"auto"});imgHeight=parHeight;imgWidth=Math.round(imgHeight*imgAspect);}}else{org_image.css({"height":parHeight+"px"});imgHeight=parHeight;imgWidth=Math.round(imgHeight*imgAspect);if((parHeight*imgAspect)<parWidth){org_image.css({"width":parWidth+"px","height":"auto"});imgWidth=parWidth;imgHeight=Math.round(imgWidth/imgAspect);}}
if(imgWidth>parWidth){org_image.css({"margin-left":"-"+Math.round((imgWidth-parWidth)/2)+"px"});}
if(imgHeight>parHeight&&opts.centerVertical){org_image.css({"margin-top":"-"+Math.round((imgHeight-parHeight)/2)+"px"});}}else{if(imgWidth>parWidth){org_image.css({"margin-left":"-"+Math.round((imgWidth-parWidth)/2)+"px"});}else if(imgWidth<parWidth){org_image.css({"margin-left":Math.round((parWidth-imgWidth)/2)+"px"});}
if(imgHeight>parHeight&&opts.centerVertical){org_image.css({"margin-top":"-"+Math.round((imgHeight-parHeight)/2)+"px"});}else if(imgHeight<parHeight&&opts.centerVertical){org_image.css({"margin-top":Math.round((parHeight-imgHeight)/2)+"px"});}}
opts.complete.call(this);if(current==len){opts.end.call(this);}}
org_image.show();}});}})(jQuery);

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

jQuery(document).ready(function(){ 

  var jobby = function slideSwitch() {
    var $active = $('#homeslide li.active');
    if ( $active.length == 0 ) $active = $('#homeslide li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#homeslide li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    }

  if ($('#homeslide').length){
    setInterval( jobby, 5000 );
  }

  var current_main = jQuery('#main_0');
  
  jQuery('.boxgrid.caption').hover(function(){  
          jQuery(".cover", this).stop().animate({top:'174px'},{queue:false,duration:160});  
      }, function() {  
          jQuery(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});  
      }); 
      
  jQuery('.galbuynow').hover(function(){
          jQuery(this).animate({right:'-100px'},{queue:false,duration:160});  
      }, function() {
          jQuery(this).animate({right:'-270px'},{queue:false,duration:160});        
      }); 
  jQuery('.galdesc').hover(function(){
          var move = jQuery(this).children().height()
          jQuery(this).animate({bottom:(-280+move)+'px'},{queue:false,duration:160});  
      }, function() {
          jQuery(this).animate({bottom:'-260px'},{queue:false,duration:160});        
      });  
  
  var config = {    
     over: function(){
        var me = jQuery(this).attr('class');
        jQuery(current_main).hide();
        jQuery('#'+me).show();
        jQuery('#'+me+' img').imgCenter({scaleToFit:false,parentSteps: 0});
        current_main = jQuery('#'+me);
      },
     timeout: 500, 
     out: function(){} 
};

  jQuery('.galthumb img').hoverIntent(config);
  jQuery('#main_0 img').imgCenter({scaleToFit:false,parentSteps: 1});

});
  
function mellerpic(picURL, pageURL, myID) {
  existingURL = jQuery('#artistimage').attr("src");
  if (existingURL != picURL) {
    jQuery('#artistimage').stop(1,0).attr("src", picURL); 
    jQuery('#artistpage').attr("href",pageURL);
    jQuery('#'+myID).siblings().removeClass("activeartist");
    jQuery('#'+myID).addClass("activeartist");
  }
}


