/*
Project: Sprague Solutions
Author: Jason Denizac @ Synoptek
Date: 4/22/2009

Dependencies: jQuery 1.2.6
*/


/*	reflection.js for jQuery v1.02	(c) 2006-2008 Christophe Beyls <http://www.digitalia.be>	MIT-style license.*/
(function(a){a.fn.extend({reflect:function(b){b=a.extend({height:0.33,opacity:0.5},b);return this.unreflect().each(function(){var c=this;if(/^img$/i.test(c.tagName)){function d(){var j,g=Math.floor(c.height*b.height),k,f,i;if(a.browser.msie){j=a("<img />").attr("src",c.src).css({width:c.width,height:c.height,marginBottom:-c.height+g,filter:"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(b.opacity*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(b.height*100)+")"})[0]}else{j=a("<canvas />")[0];if(!j.getContext){return}f=j.getContext("2d");try{a(j).attr({width:c.width,height:g});f.save();f.translate(0,c.height-1);f.scale(1,-1);f.drawImage(c,0,0,c.width,c.height);f.restore();f.globalCompositeOperation="destination-out";i=f.createLinearGradient(0,0,0,g);i.addColorStop(0,"rgba(255, 255, 255, "+(1-b.opacity)+")");i.addColorStop(1,"rgba(255, 255, 255, 1.0)");f.fillStyle=i;f.rect(0,0,c.width,g);f.fill()}catch(h){return}}a(j).css({display:"block",border:0});k=a(/^a$/i.test(c.parentNode.tagName)?"<div />":"<div />").insertAfter(c).append([c,j])[0];k.className=c.className;a.data(c,"reflected",k.style.cssText=c.style.cssText);a(k).css({width:c.width,height:c.height+g,overflow:"hidden"});c.style.cssText="display: block; border: 0px";c.className="reflected"}if(c.complete){d()}else{a(c).load(d)}}})},unreflect:function(){return this.unbind("load").each(function(){var c=this,b=a.data(this,"reflected"),d;if(b!==undefined){d=c.parentNode;c.className=d.className;c.style.cssText=b;a.removeData(c,"reflected");d.parentNode.replaceChild(c,d)}})}})})(jQuery);

/* functions */



function spShowLrg(src){
	var _src = src.replace(/thm_/,"");
	jQuery("#spGalLrg").attr("src",_src);
}

/********************* Project Code *********/

function spIntGalShow(id){

		var url = "/InteriorGalelryProjectViewAJAX/tabid/126/xmmid/456/xmid/"+id+"/xmview/2/Default.aspx";
		jQuery("#dnn_ctr452_ModuleContent").load(url+" #dnn_ctr456_ModuleContent");
		return false;

}

jQuery.noConflict(); //make it play nice with DNN... must use "jQuery(...)" rather than "$(...)"

jQuery(document).ready(function(){

if(jQuery("#spGalNav").length!=0){

jQuery('#spGalNav ul img').reflect({height: 0.2, opacity: 0.6});

jQuery("#spGalNav a").click(function(){ 
	var id = jQuery(this).attr("rel");
	jQuery(this).attr("onclick","return false;");
	spIntGalShow(jQuery(this).attr("rel")); 

	jQuery("#spGalNav li").removeClass("lmCur");
	jQuery(this).parent().addClass("lmCur");
	return false;
});


var scrollspeed = 1;
var selector = "#spGalNav ul";
var speed = "fast";
numtoshow = 6;
numtotal = jQuery(selector+" li").length;
totWidth = 200;

jQuery(selector+" li").each(function(){
totWidth+= jQuery(this).width();
});
jQuery("#spGalNavList").css({width:totWidth+"px"});
sliderbar = jQuery(".spGalNavSliderBar");
maxdrag = jQuery("#spGalNavSlider").width() - sliderbar.width();
var tlc = jQuery("#spGalNavList li:last-child")
maxscroll = tlc.position().left-710+tlc.width();


function onDrag(){

var me = sliderbar;
var maxval = maxdrag;
var val = me.css('left').replace("px","");
var percent = val / maxval;

var maxw = maxscroll;
var offset = Math.floor(-maxw*percent)

jQuery("#spGalNavList").css("left",offset+"px");

}

function scNext(){
var maxval = maxdrag;
var slider = jQuery('.spGalNavSliderBar');
var left = slider.css("left").replace("px","");
var speedd = -20;
if(left<maxval) {slider.css("left",(left-speedd)+"px");}
else{ slider.css("left",maxval+"px");}
onDrag();
return false;
}

function scPrev(){
var slider = jQuery('.spGalNavSliderBar');
var left = slider.css("left").replace("px","");
var speedd = 20;
if(left>20){ slider.css("left",left-speedd+"px");}
else{ slider.css("left","0px");}
onDrag();
return false;
}

jQuery('.spGalNavNext').click(scNext);
jQuery('.spGalNavPrev').click(scPrev);
jQuery('.spGalNavSliderBar').draggable({axis:'x', containment: 'parent', cursor: 'E-resize',  drag: onDrag, stop: onDrag});

var curid = jQuery("#spGalThumbs").attr("class").replace(/spIntGalItem/,"");
jQuery("a[rel="+curid+"]").parent().addClass("lmCur");

}
else if(jQuery(".spFurnGalTop").length!=0){


jQuery("#spFeaturedProducts li:nth-child(4n)").css("clear","left");
jQuery("#spFeaturedProducts li:nth-child(3n)").css("padding-right","0");
// remove link background images since we're re-doing the hover interaction below 
		// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
		// we also want to only remove the image on non-selected nav items, so this is a bit more complicated


jQuery(".spFurnGalTop li:not(.lmCur)").mouseover(function(){
jQuery(this).addClass("lmCur").stop().fadeTo(0,1);
}).mouseout(function(){
jQuery(this).addClass("").fadeTo(500, 0, function(){ jQuery(this).removeClass("lmCur").fadeTo(0,1); });
});





}

/* open external links in new window
jQuery("a").filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).attr("target","_blank");*/




});


