//lightbox
(function($){$.fn.lightBox=function(settings){settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading:'assets/rbimages/lb/lightbox-ico-loading.gif',imageBtnPrev:'assets/rbimages/lb/lightbox-btn-prev.gif',imageBtnNext:'assets/rbimages/lb/lightbox-btn-next.gif',imageBtnClose:'assets/rbimages/lb/lightbox-btn-close.gif',imageBlank:'assets/rbimages/lb/lightbox-blank.gif',containerBorderSize:10,containerResizeSpeed:400,txtImage:'Image',txtOf:'of',keyToClose:'c',keyToPrev:'p',keyToNext:'n',imageArray:[],activeImage:0},settings);var jQueryMatchedObj=this;function _initialize(){_start(this,jQueryMatchedObj);return false}function _start(objClicked,jQueryMatchedObj){$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')))}else{for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')))}}while(settings.imageArray[settings.activeImage][0]!=objClicked.getAttribute('href')){settings.activeImage++}_set_image_to_view()}function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+settings.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+settings.imageBtnClose+'"></a></div></div></div></div>');var arrPageSizes=___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]}).show();$('#jquery-overlay,#jquery-lightbox').click(function(){_finish()});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){_finish();return false});$(window).resize(function(){var arrPageSizes=___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]})})}function _set_image_to_view(){$('#lightbox-loading').show();if(settings.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()}else{$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()}var objImagePreloader=new Image();objImagePreloader.onload=function(){$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);objImagePreloader.onload=function(){}};objImagePreloader.src=settings.imageArray[settings.activeImage][0]};function _resize_container_image_box(intImageWidth,intImageHeight){var intCurrentWidth=$('#lightbox-container-image-box').width();var intCurrentHeight=$('#lightbox-container-image-box').height();var intWidth=(intImageWidth+(settings.containerBorderSize*2));var intHeight=(intImageHeight+(settings.containerBorderSize*2));var intDiffW=intCurrentWidth-intWidth;var intDiffH=intCurrentHeight-intHeight;$('#lightbox-container-image-box').animate({width:intWidth,height:intHeight},settings.containerResizeSpeed,function(){_show_image()});if((intDiffW==0)&&(intDiffH==0)){if($.browser.msie){___pause(250)}else{___pause(100)}}$('#lightbox-container-image-data-box').css({width:intImageWidth});$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:intImageHeight+(settings.containerBorderSize*2)})};function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();_set_navigation()});_preload_neighbor_images()};function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(settings.imageArray[settings.activeImage][1]){$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show()}if(settings.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(settings.txtImage+' '+(settings.activeImage+1)+' '+settings.txtOf+' '+settings.imageArray.length).show()}}function _set_navigation(){$('#lightbox-nav').show();$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({'background':'transparent url('+settings.imageBlank+') no-repeat'});if(settings.activeImage!=0){if(settings.fixedNavigation){$('#lightbox-nav-btnPrev').css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false})}else{$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'})},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'})}).show().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false})}}if(settings.activeImage!=(settings.imageArray.length-1)){if(settings.fixedNavigation){$('#lightbox-nav-btnNext').css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false})}else{$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'})},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'})}).show().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false})}}_enable_keyboard_navigation()}function _enable_keyboard_navigation(){$(document).keydown(function(objEvent){_keyboard_action(objEvent)})}function _disable_keyboard_navigation(){$(document).unbind()}function _keyboard_action(objEvent){if(objEvent==null){keycode=event.keyCode;escapeKey=27}else{keycode=objEvent.keyCode;escapeKey=objEvent.DOM_VK_ESCAPE}if(escapeKey==undefined){escapeKey=27}key=String.fromCharCode(keycode).toLowerCase();if((key==settings.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish()}if((key==settings.keyToPrev)||(keycode==37)){if(settings.activeImage!=0){settings.activeImage=settings.activeImage-1;_set_image_to_view();_disable_keyboard_navigation()}}if((key==settings.keyToNext)||(keycode==39)){if(settings.activeImage!=(settings.imageArray.length-1)){settings.activeImage=settings.activeImage+1;_set_image_to_view();_disable_keyboard_navigation()}}}function _preload_neighbor_images(){if((settings.imageArray.length-1)>settings.activeImage){objNext=new Image();objNext.src=settings.imageArray[settings.activeImage+1][0]}if(settings.activeImage>0){objPrev=new Image();objPrev.src=settings.imageArray[settings.activeImage-1][0]}}function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove()});$('embed, object, select').css({'visibility':'visible'})}function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(xScroll<windowWidth){pageWidth=xScroll}else{pageWidth=windowWidth}arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize};function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft}arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll};function ___pause(ms){var date=new Date();curDate=null;do{var curDate=new Date()}while(curDate-date<ms)};return this.unbind('click').click(_initialize)}})(jQuery);
/* jqModal Version: 03/01/2009 +r14 */
(function($){$.fn.jqm=function(o){var p={overlay:50,overlayClass:'jqmOverlay',closeClass:'jqmClose',trigger:'.jqModal',ajax:F,ajaxText:'',target:F,modal:F,toTop:F,onShow:F,onHide:F,onLoad:F};return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};if(p.trigger)$(this).jqmAddTrigger(p.trigger)})};$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide')};$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow')};$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t)})};$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)})};$.jqm={hash:{},open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);if(c.modal){if(!A[0])L('bind');A.push(s)}else if(c.overlay>0)h.w.jqmAddClose(o);else o=F;h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in{Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'")}}if(c.ajax){var r=c.target||h.w,u=c.ajax,r=(typeof r=='string')?$(r,h.w):$(r),u=(u.substr(0,1)=='@')?$(t).attr(u.substring(1)):u;r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h)})}else if(cc)h.w.jqmAddClose($(cc,h.w));if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);(c.onShow)?c.onShow(h):h.w.show();e(h);return F},close:function(s){var h=H[s];if(!h.a)return F;h.a=F;if(A[0]){A.pop();if(!A[0])L('unbind')}if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove()}return F},params:{}};var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version=="6.0"),F=false,i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i);f(h)},f=function(h){try{$(':input:visible',h.w)[0].focus()}catch(_){}},L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m)},m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return!r},hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function(){if(!this[c]){this[c]=[];$(this).click(function(){for(var i in{jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F})}this[c].push(s)})})}})(jQuery);


var currentImage = 'image1';
var images = new Array();


$(document).ready(function(){
					  
					  
	var divHeight = document.getElementById("mainDescription").offsetHeight;
	var lineHeight = parseInt($('#mainDescription').css('line-height'));
	var lineCount = divHeight / lineHeight;

	if(lineCount >4) {
		$('#mainDescription').height(	4 * parseInt($('#mainDescription').css('line-height')));
		$('#mainDescription').css('overflow', 'hidden');
		$('#mainDescription').after('<div id="mainMore"><h5><span class="little">&nbsp;</span>More&hellip;</h5></div>');
	};

/*--main text collapse--*/

	$('#mainMore h5').css('cursor', 'pointer');

	$('#mainMore h5').toggle(
	  function(){
		$(this).html('<span class="little">&nbsp;</span>Less&hellip;');
	    $(this).find('span').css('background-position', 'bottom left');
	    $('#mainDescription').height(divHeight);
	  },
	  function(){
		  $(this).html('<span class="little">&nbsp;</span>More&hellip;');
	    $(this).find('span').css('background-position', 'top left');
	    $('#mainDescription').height(	4 * parseInt($('#mainDescription').css('line-height')));
	  }
	);				  
					  
					  


	$('a.external').attr('target','_blank');
	$('#modallogin').jqm({modal: true, trigger: '#banner .login a',overlay:75});
	if($("body").height() < $(document).height()) {
		$('#pagewrapper').height($(document).height());
	}
	else {
		$('#pagewrapper').height($("body").height());
	}
	
	var	imagecontainer	=	$('.images');
	var productthumbs	=	$('.thumbs',imagecontainer);
	$('li a',productthumbs).hover(function(){
		if($(this).attr('href')==$('.main img',imagecontainer).attr('src'))
			return false;
	
		i 		= new Image();
		i.src	= $(this).attr('href');
		i.alt	= '';
		$(i).load(function(){
			$(this).hide().fadeIn();
			$('.main',imagecontainer).html(i);
		});
		return false;
	});	
	//$('a',productthumbs).lightBox();
	
	$('#sidebar .content a').lightBox();
	
	
	
	/* gallery */
    
    resizeImage();
    
    $('.thumbs img').click(function(){
		$('.thumbs img').addClass('inactive');
		$('.thumbs img').removeClass('active');
		imgSrc = $(this).attr("src");
		
		imgSrcArr = imgSrc.split(".thumb_");
		imgSrc = imgSrcArr[0]+""+imgSrcArr[1];
		myImg = imgSrc;
		$(this).removeClass('inactive');
		$(this).addClass('active');
		$('#loader').fadeIn('fast',function(){
			$('.image').html('<a href="'+myImg+'"><img src="'+myImg+'" /><span id="magnify">Click to enlarge</span></a>');
			setTimeout(function(){ resizeImage(); },400);						 
		});
		currentImage = $(this).attr('class');
	});
    
    $('.image a').click(function(e){
		e.preventdefault();
		modalGallery();
	});
    
    
	$('ul.gallery_tabs li').css('cursor', 'pointer');	
	$('ul.gallery_tabs li').click(function(){
		if($(this).attr('id')=='videotab'){
			videosOn();
		} else {
			imagesOn();
		}
	});
	
	
	function resizeImage() {
		$('body #mBody').remove();
		if ($('.image img').height() > $('.image img').width()) {
			var w = 380;
		    	var h = (380 / $('.image img').width()) * $('.image img').height();
    			
		} else {
			var h = 380;
			var w = (380 / $('.image img').height()) * $('.image img').width();
			
		}
		var boxLeft = (380 - w) / 2;
		var boxTop = (380 - h) / 2;
	  	
		$('.image').css('overflow', 'hidden');
		$('#loader').delay(500).fadeOut('fast');
		$('.image img').css({ height: h, width: w, position: 'absolute', top: boxTop, left: boxLeft });
		$('.image a').click(function(e){
			e.preventDefault();	
			modalGallery();
							    
		});
	};
	
	function modalGallery() {
		currentImage = currentImage.replace('active','');
		currentImage = currentImage.replace('image','');
		var currentImageNum = parseInt(currentImage) - 1;
		
		var i = 0;
		$('.thumbs img').each(function(){
			var imgsrcArr = $(this).attr("src").split(".thumb_");
			images[i] = imgsrc = (imgsrcArr[0]+""+imgsrcArr[1]);	
			i++;
		});
		var mBox = "<div id='mBody'>";
		mBox += "<div id='mOverlay'></div>";
		mBox += "<div id='mBox'>";
		mBox += "<div id='mContent'>";
		mBox += "<div id='mImage'><img src='"+images[currentImageNum]+"' /></div>";
		mBox += "<div id='mDescription'><span class='imageNumber'>Image "+(currentImageNum+1)+" of "+(i)+"</span><span class='close'>close</span><div class='clear'>&nbsp;</div></div>";
		if(currentImageNum!=0){
			mBox += "<div id='mPrev'>Previous</div>";
		}
		if(currentImageNum!=i-1){
			mBox += "<div id='mNext'>Next</div>";
		}
		mBox += "</div><!-- end #mContent --></div><!-- end #mBox --></div><!-- end #mBody -->";
		
		
		
		$('body').append(mBox);
		
		$('#mOverlay').click(function(){
			$('body #mBody').remove();						
		});
		
		$("#mContent img").load(function () {	
			repos();
			$(window).resize(function() {
				
 				
			});

			$('#mBody .close').click(function(){
				$('body #mBody').remove();	
			});


			$('#mBody #mPrev').click(function(){
				currentImageNum = (currentImageNum-1);
				modalUpdate();
			});
			$('#mBody #mNext').click(function(){
				currentImageNum = (currentImageNum+1);
				modalUpdate();
			});


			function modalUpdate(){
				$("#mBox").css('top',-1000);
				$('#mBox').html('');
				var mBox = "<div id='mContent'>";
				mBox += "<div id='mImage'><img src='"+images[currentImageNum]+"' /></div>";
				mBox += "<div id='mDescription'><span class='imageNumber'>Image "+(currentImageNum+1)+" of "+(i)+"</span><span class='close'>close</span><div class='clear'>&nbsp;</div></div>";
				if(currentImageNum!=0){
					mBox += "<div id='mPrev'>Previous</div>";
				}
				if(currentImageNum!=i-1){
					mBox += "<div id='mNext'>Next</div>";
				}
				mBox += "</div><!-- end #mContent -->";
				$('#mBox').html(mBox);
				$("#mContent img").load(function () {	
					repos();
				});
				$('#mBody .close').click(function(){
					
					$('body #mBody').remove();	
				});
				$('#mBody #mPrev').click(function(){
										    
					currentImageNum = (currentImageNum-1);
					modalUpdate();
				});
				$('#mBody #mNext').click(function(){
					currentImageNum = (currentImageNum+1);
					modalUpdate();
				});
			}


			function repos(){
				
				var posLeft = ($('body').width() - $('#mContent img').width()) / 2;
				$("#mBox").css('left', posLeft);
				
				$("#mBox").css('width', $('#mContent img').width());
				$("#mBox").css('height', $('#mContent img').height()+40);
				$("#mBox #mPrev").css('top', $('#mContent img').height() / 2);
				$("#mBox #mNext").css('top', $('#mContent img').height() / 2);
				$("#mBox").hide();
				$("#mBox").css('top', 90);
				$("#mBox").fadeIn('fast');
			}
		});

		
	}
	
	/* video */
	$('.videoThumb').click(function(){
		var myLinkID = $(this).find('img').attr('data-link');
		var newFrame = '<iframe title="YouTube video player" class="youtube-player" type="text/html" width="380" height="230" src="http://www.youtube.com/embed/'+myLinkID+'" frameborder="0" allowFullScreen></iframe>';
		$('#videos .video').html(newFrame);
		$('.videoThumb').removeClass('playing');
		$(this).addClass('playing');
	});
	
	
	function videosOn(){
		$('#videos').css('display', 'block');
		$('#videotab').addClass('active').removeClass('inactive');
		$('#images').css('display', 'none');
		$('#imagetab').addClass('inactive').removeClass('active');
	}
	
	function imagesOn(){
		$('#images').css('display', 'block');
		$('#imagetab').addClass('active').removeClass('inactive');
		$('#videos').css('display', 'none');
		$('#videotab').addClass('inactive').removeClass('active');
		
	}
	

	
});


