/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2009 Brand Labs LLC
 * 
 * Alternate Image Video
 * 
 * Version 1.1.1
 * 
 *--------------------------------------------------------------------------*/
var Video=Class.create({DEFAULT_PARAMS:{base:null,flashvars:null},initialize:function(aa,ba,ca,da){this.settings=new Hash(arguments[4]||{}).clone();this.thumbnailSource=ba;this.source=aa;this.height=da;this.width=ca;this.parameters=new Hash(this.DEFAULT_PARAMS).clone();},createThumbnailElement:function(){var ea=null;var fa=new Element('img',{src:this.thumbnailSource,alt:'Product Video',title:'Product Video',border:'1'});fa.setStyle({borderColor:'#666666'});fa.addClassName('alternate_product_photo_video');ea=new Element('a',{href:'javascript: void(0);',onclick:'javascript: return false;'});ea.insert(fa);return ea;},createAndDisplayElement:function(ga){var ha=new Element('div');var id=ha.identify();ha.setStyle({display:'none'});ga.insert(ha);return swfobject.createSWF({data:this.source,width:this.width,height:this.height,'class':'product_photo_video',classid:'clsid:D27CDB6E-AE6D-11CF-96B8-444553540000',codebase:'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0'},this.parameters.toObject(),id);},getLargerSource:function(){var ia=null;ia=this.settings.get('large_source');if(ia==null){ia=this.source;}
return ia;}});var AlternateImageVideo=Class.create({DEFAULT_SETTINGS:{DEFAULT_PARAMS:{swliveconnect:false,play:true,loop:false,menu:false,quality:'autohigh',scale:'noorder',wmode:'transparent',bgcolor:null,allowscriptaccess:false,allowfullscreen:false,allownetworking:true},ALTERNATE_PHOTO_SELECTOR:'a[href^="javascript:change_product_photo("] img[id^="alternate_product_photo_"]',CHANGE_LARGER_PHOTO_BUTTON:true,LARGER_PHOTO_BUTTON_SOURCE:null},initialize:function(ja,ka){try{this.settings=new Hash(this.DEFAULT_SETTINGS).clone();this.settings.update(new Hash(arguments[2]||{}));if(typeof change_product_photo=='undefined'){return;}
this.changeProductPhotoFunction=change_product_photo;change_product_photo=this.changeProductPhotoProxy.bind(this);if(ja==null){return;}
this.videos=ja;this.parameters=new Hash(this.settings.get('DEFAULT_PARAMS')).clone();this.parameters.set('bgcolor',ka);this.videos.each(function(la){if(la.parameters==null||this.parameters==null){return;}
la.parameters.update(this.parameters);},this);this.currentVideoElement=null;this.currentVideo=null;this.videoLocation=null;this.productPhotoAnchor=null;this.originalLargerPhotoButtonSource=null;Event.observe(window,'load',this.load.bind(this));}
catch(e){}},load:function(){try{this.productPhotoAnchor=$('product_photo_zoom_url');if(this.productPhotoAnchor==null){return;}
this.videoLocation=new Element('div',{id:'product_photo_video_container'});this.videoLocation.hide();this.productPhotoAnchor.insert({after:this.videoLocation});this.addThumbnails();if(this.settings.get('CHANGE_LARGER_PHOTO_BUTTON')&&this.settings.get('LARGER_PHOTO_BUTTON_SOURCE')!=null){new Element('img',{src:this.settings.get('LARGER_PHOTO_BUTTON_SOURCE')});}}
catch(e){}},addThumbnails:function(){var ma=$$(this.settings.get('ALTERNATE_PHOTO_SELECTOR'));var na=null;na=ma.last().up();this.videos.each(function(oa){var pa=oa.createThumbnailElement();Event.observe(pa,'click',this.showVideo.bind(this,oa,pa));na.insert({after:pa});na=pa;na.setStyle({marginLeft:'4px'});},this);},showVideo:function(){var qa=$A(arguments);var ra=null;var sa=null;var ta=null;try{if(qa.length<2){return;}
ra=qa[0];sa=qa[1];if(this.currentVideo!=null&&this.currentVideo==ra){return;}
this.currentVideo=ra;if(this.productPhotoAnchor.visible()){this.productPhotoAnchor.hide();}
if(this.currentVideoElement!=null){this.currentVideoElement.remove();this.currentVideoElement=null;}
this.currentVideoElement=$(ra.createAndDisplayElement(this.videoLocation));if(this.settings.get('CHANGE_LARGER_PHOTO_BUTTON')){ta=$('product_photo_zoom_url2');if(ta!=null){ta.writeAttribute({href:'javascript:OpenNewWindow(\''+ra.getLargerSource()+'\', 640, 600);'});ta=ta.down();if(ta!=null&&this.settings.get('LARGER_PHOTO_BUTTON_SOURCE')!=null){this.originalLargerPhotoButtonSource=ta.readAttribute('src');ta.writeAttribute({src:this.settings.get('LARGER_PHOTO_BUTTON_SOURCE')});}}}
this.changeBorders(sa);this.videoLocation.show();}
catch(e){}},changeBorders:function(ua){$$('.alternate_product_photo_video').each(function(va){va.writeAttribute({border:1});});$$(this.settings.get('ALTERNATE_PHOTO_SELECTOR')).each(function(wa){wa.writeAttribute({border:1});});if(ua!=null){ua.down().writeAttribute({border:2});}},changeProductPhotoProxy:function(xa){try{if(this.currentVideoElement!=null){this.currentVideoElement.remove();this.currentVideoElement=null;this.currentVideo=null;}
if(this.videoLocation!=null){this.videoLocation.hide();}
if(!this.productPhotoAnchor.visible()){this.productPhotoAnchor.show();}
this.changeBorders(null);if(this.originalLargerPhotoButtonSource!=null){largerPhotoButton=$('product_photo_zoom_url2');if(largerPhotoButton!=null){largerPhotoButton=largerPhotoButton.down();}
if(largerPhotoButton!=null){largerPhotoButton.writeAttribute({src:this.originalLargerPhotoButtonSource});}
this.originalLargerPhotoButtonSource=null;}
this.changeProductPhotoFunction(xa);}
catch(e){}}});
