function mailpage(){
	var SubjectLine='See this ECS Case page: '+document.title;
	var BodyText='See this ECS Case page at: '+location.href;
	location.href= 'mailto:?SUBJECT='+encodeURI(SubjectLine)+'&BODY='+escape(BodyText);
}

(function($){
	var cache = [];
	$.preLoadImages = function(){
		for(var i = arguments.length;i--;){
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery);


// EXTERNAL INTERFACE functions from flash
function hidePosterFrame(hideThis){
	// alert ('hide');
	jQuery("#"+hideThis).animate({opacity:0});
}
function showPosterFrame(showThis){
	jQuery("#"+showThis).animate({opacity:1});
}
function ga_trackPlay(videoIdentifier)
{
	_gaq.push(['_trackEvent', 'Video', 'Play', videoIdentifier]);
}
function ga_trackVidComplete(videoIdentifier)
{
	_gaq.push(['_trackEvent', 'Video', 'Complete', videoIdentifier]);
}

function initialize_select_color_box ()
{
	(function($) {
	
	// IF THERE IS A COLOR SELECTOR AND A SWATCH, ACTIVATE IT SUCH THAT WHEN IT IS CHANGED, THE CORRECT SWATCH IS CLICKED

	if ($('#SelectColorCont select:not(.initialized)').length > 0 && $('.media_holder_master .swatches_holder .swatch').length > 0)
	{
		//alert('has colors');

		$('#SelectColorCont select').addClass('initialized').change(function() {
			//alert('change');
			var color_val = jQuery.trim($(this).find(':selected').html().toLowerCase()).replace(' ', '-');
			$('.media_holder_master .swatches_holder .swatch[swatchcolor="'+color_val+'"]:eq(0)').click();
		});
	}
	
	})(jQuery);
}

function initialize_product_page_gallery ()
{
	(function($) {

		// CLICKING OF MAIN HERO SHOULD CAUSE A LIGHTBOX
		$("a.lb").fancybox(
			{
				'titleShow':false,
				'overlayOpacity':.85,
				'overlayColor':'#000',
				'centerOnScroll':true,
				'autodimensions':true,
				'padding':0,
				'margin':0,
				'scrolling':'no'
			}
		);
		// CLICKING A VIDEO SHOULD BRING THAT VIDEO UP IN A LIGHTBOX
		$(".vidLb").click(function() {        
		    $.fancybox(
		    	{
		    		'titleShow':false,
		    		'overlayOpacity':.85,
		    		'overlayColor':'#000',
		    		'centerOnScroll':true,
		    		'autodimensions':true,
		    		'padding':0,
		    		'margin':0,
		    		'scrolling':'no',
		    		'width':853,
		    		'height':505,
		    		'href':this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
		    		'type':'swf',
		    		'swf':
		    			{
						'wmode':'transparent',
		    				'allowfullscreen':'true'
		    			}
		    	}
		    );
		    return false;
		});
		
		/* $(".vidPlayer").click(function(){
		    $.fancybox({'titleShow':false,'overlayOpacity':.85,'overlayColor':'#000','centerOnScroll':true,'autodimensions':true,'padding':0,'margin':0,'scrolling':'no','width':853,'height':505,'href':this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),'type':'swf','swf':{'wmode':'transparent','allowfullscreen':'true'}});
		    return false;
		});*/
		// fancy box on main image
		// $(".lb360").fancybox({'titleShow': false,'overlayOpacity':.85,'overlayColor':'#000','centerOnScroll':true,'autodimensions':true,'width':682,'height':500,'padding':0,'margin':0,'scrolling':'no'});
		
		/*
		if ($('.imgGallThumb').length>1){
			$.each($('.imgGallThumb'),function(){
				if ($(this).attr('title')!='Hero'){
					// $(this).append('')
				}
				
			});
			
		}
		*/
		
		
		// set the color val for cart initially
		$('#color_val_for_cart').val($('#image').attr('src'));
		
		var thisSrc;	
		
		// START MEDIA THUMBS
		$('.imgGallThumb').click(function(){
		
			// if a swatch color is chosen, default to swatch color for hero display
			if ($(this).attr('id')=='HeroThumb')
			{
				thisSrc = $(this).attr('rel');
				$.each($('.swatch'),function(){
					if ($(this).hasClass('swatch-act')){
						thisSrc = $('.swatch-act').attr('rel');
					}
				});
			}
			else
			{
				thisSrc = $(this).attr('rel');
			}
			
		    $('.product_page_media .media_holder_master .image_holder .lb').attr('href', thisSrc).find('#image').attr('src', thisSrc);
			$('#color_val_for_cart').val(thisSrc);
		    	
			$('.product_page_media .media_holder_master .video_holder').hide(0);
			$('.product_page_media .media_holder_master .three60_holder').hide(0);
			$('.product_page_media .media_holder_master .image_holder').show(0);
			$('.product_page_media .image_info').show(0);
			
			
			// IF IT IS A SWATCH
			if ($(this).hasClass('swatch'))
			{
				var clicked_obj = $(this);
				
				// IF A COLOR SELECTOR EXISTS AND THE SWATCH HAS A COLOR ASSIGNED
				if ($('#SelectColorCont select').length > 0 && $(this).attr('swatchcolor'))
				{
					// GO THROUGH EACH COLOR, AND SEE IF IT MATCHES
					$('#SelectColorCont select option').each(function() {
						if (jQuery.trim($(this).html()).toLowerCase().replace(' ', '-') == $(clicked_obj).attr('swatchcolor'))
						{
							$(this).parent().val($(this).val());
						
						}
					});
				}
			
				// remove active class from others, add to this swatch
				$.each($$('.swatch'),function(){$(this).removeClass('swatch-act');});
				$(this).addClass('swatch-act');
			}
			else
			{
				if ($(this).attr('id')=='HeroThumb')
				{
					$('.swatches_holder').show(0);
					$.each($$('.swatch'),function(){
						if ($(this).hasClass('swatch-act'))
						{
							$(this).click();
						}
					});				
				}
				else
				{
					$('.swatches_holder').hide(0);	
				}
			}
		});
		// END MEDIA THUMBS
		
		// SELECT COLOR BOX
		initialize_select_color_box();
		
		// START VIDEO CLICK
		$('.vidThumb').click(function(){
			
			$('.product_page_media .media_holder_master .image_holder').hide(0);
			$('.product_page_media .media_holder_master .three60_holder').hide(0);
			$('.product_page_media .image_info').hide(0);
			$('.product_page_media .media_holder_master .video_holder').show(0);
			
			if (check_if_ios() === true)
            {
            	var video = $(this).attr('rel');
            	video = video.replace('.flv', '.mp4');
            	var path = "/media/video/mp4_converted_for_web/"+video;
            	var html = '<video width="415" height="233" controls autoplay><source src="'+path+'" type="video/mp4"></source></video>';
            	$('#video_holder').html(html);
            }
            else
            {
				var thisFlashVars = $(this).attr('rel');

				var flashvars = {'playbackSource':thisFlashVars};
			    var params = {};
			    params.wmode = "transparent";
			    params.allowFullScreen= true;
			    params.scale="noscale"
			    params.align="TL";
			    params.allowScriptAccess="always";
			    var attributes = {};
			    swfobject.embedSWF("/media/video/videoPlayer_415x233.swf", "video_holder", "415", "233", "9.0.0","expressInstall.swf", flashvars, params, attributes);
			}
		});
		// END VIDEO CLICK
		
		// START 360 CLICK
		$('.thumb-360').click(function(){
			var thisFlashVars = $(this).attr('rel');
			
			$('.product_page_media .media_holder_master .image_holder').hide(0);
			$('.product_page_media .media_holder_master .video_holder').hide(0);
			$('.product_page_media .image_info').hide(0);
			$('.product_page_media .media_holder_master .three60_holder').show(0);
			
		    var flashvars = false;
		    var params = {flashvars:thisFlashVars};
		    params.wmode = "transparent";
		    params.allowFullScreen= true;
		    params.scale="scale"
		    params.align="TL";
		    params.allowScriptAccess="always";
		    var attributes = {};
		    swfobject.embedSWF("/media/prod360/viewer.swf", "three60_holder", "415", "300", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		});
		// END 360 CLICK
		
		// bring in color swatches
		//if($('.product_page_media .image_info').length>0) $('.product_page_media .image_info').slideDown(500);
		
		// START CLICKING A MEDIA TYPE (GALLERY, VIDEO, 360)
		$('#mediaTog a').click(function(){
		    $('.thumbStripCont').css('display','none');
		
			$('#mediaTog a').removeClass('togAct');
			$(this).addClass('togAct');
		    $('#mediaTog a').removeClass('togAct');
		    var togCont = '#thumbStripCont'+$(this).attr('id').replace('tog','');
		    $(togCont).css('display','block');
		    $(this).addClass('togAct');
		
		    if ($(this).html()=='VIDEO')
		    {
		    	$(togCont).find('.vidThumb:eq(0)').click();
		    }
		    else if ($(this).html()=='360')
		    {
		
		        $(togCont).find('.thumb-360:eq(0)').click();
		    }
		    else
		    {
		        $(togCont).find('.imgGallThumb:eq(0)').click();
		
		    }
		});
		// END CLICKING A MEDIA TYPE (GALLERY, VIDEO, 360)
		
		// START CAROUSEL
		if ($$('#thumbStripCont1').length>0)
		{
		    jQuery('#thumbStripCont1').jcarousel();
		}
		if ($$('#thumbStripCont2').length>0)
		{
		    jQuery('#thumbStripCont2').jcarousel();
		}
		if ($$('#thumbStripCont3').length>0)
		{
		    jQuery('#thumbStripCont3').jcarousel();
		}
		// END CAROUSEL
	
	})(jQuery);
}

function show_dynamic_quote_only_form ()
{
	(function($) {
	
		var newDiv = $('<div id="dynQuoteOnly"></div>');
		var formHTML = $('#quote-only-holder .copyable').html();
		
		$(newDiv).html('<br /><strong>The option you selected is only available by quote.</strong><br />Please fill out the form below, or <a href="#" onclick="jQuery(\'#dynQuoteOnly\').remove(); jQuery(\'#optionsContAll\').show(0); return false;">go back to options</a>.<br /><br />'+formHTML);
		
		$('#optionsContAll').hide(0).after(newDiv);
		
		$('#dynQuoteOnly form').removeClass('initialized');
		
		initialize_quote_form();
		
	})(jQuery);
}

function isEmpty(string){
	string = jQuery.trim(string);
    if (string == "" || string == null){
    	return true;
    }else{
    	return false;
    }
}
	
function isEmail(email_string){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if(email_string.search(validRegExp) == -1) return false;
	else return true; 
}

function validate_form(form_selector){
	var return_val = true;
	(function($) {
		$(form_selector+' .required').each(function(){
			var tmp_valid = true;
			var form = this.form;
			if($(this).is('textarea')){
				// MAKE SURE HAS TEXT
				if(isEmpty($(this).val())) tmp_valid = false;
			}else if($(this).is('input')){
				switch ($(this).attr('type')){
					case 'radio':
						// MAKE SURE AT LEAST ONE OF THIS NAME IS CHECKED
						if($(form).find('input[name="'+$(this).attr('name')+'"]:checked').length == 0) tmp_valid = false;
						break;
					case 'checkbox':
						// MAKE SURE IS CHECKED
						if($(this).attr('checked') != 'checked') tmp_valid = false;
						break;
					case 'text':
						// MAKE SURE HAS TEXT
						if(isEmpty($(this).val())) tmp_valid = false;
						break;
				}
			}
			
			if(tmp_valid && $(this).hasClass('is_email')) tmp_valid = isEmail($(this).val());
			
			if(tmp_valid){
				$(form).find('.validator_'+$(this).attr('name')).removeClass('validator_invalid');
				$(form).find('.validator_border_'+$(this).attr('name')).removeClass('validator_invalid_border');
			}else{
				$(form).find('.validator_'+$(this).attr('name')).addClass('validator_invalid');
				$(form).find('.validator_border_'+$(this).attr('name')).addClass('validator_invalid_border');
				return_val = false;
			}
		});
	})(jQuery);
	return return_val;
}

function initialize_quote_form ()
{
	(function($) {

		// quote form validation
	    if($('.quote-product-form:not(.initialized)').length){
	    	$('.quote-product-form:not(.initialized)').addClass('initialized').submit(function(){
	    		var form = $(this);
	    		var uniqid = new Date().getTime();
	    		$(form).attr('id', 'quote-product-form-'+uniqid);
	    		var is_validated = validate_form('#'+$(form).attr('id'));
	    		if(is_validated)
	    		{

	
	                    // SEND THE QUOTE REQUEST 
	                    $.ajax({
	                          url: '/ecsmail/sendemail/sendProductQuote',
	                          type:'POST',
	                          data:$(form).serialize(),
	                          success:function(data){
	                            if (data.search('emailSent')){
	                                $.fancybox({'padding':0,'content':"<div style='padding:10px; width:250px; font-size:12px;'><strong>Thank you for your inquiry!</strong><br /><br />We will respond to you shortly.</div>",'onComplete':function(){jQuery('.quote-product-form input, .quote-product-form textarea').not(':hidden').val('')}});
	                            }
	                          }
	                    });
	    		}
	    		else
	    		{

	    		}
	    		return false;
	    	});
	    }
    
    })(jQuery);
}

jQuery(window).ready(function($) {
	// START INITIALIZE PRODUCT PAGE GALLERY STUFF
    if ($('#image')) // if there is a main product hero graphic on the page
    {
		initialize_product_page_gallery();
    }
    // STOP INITIALIZE PRODUCT PAGE GALLERY STUFF
});

function track_pdfs ()
{
	(function($) {

		$("a[href*=.pdf]:not(.ga_tracked)").each(function(){
			$(this).addClass('.ga_tracked');
			$(this).click(function() {
				_gaq.push(['_trackEvent', 'PDF', 'Open', jQuery(this).attr('href')]);
			});
		});
	
	})(jQuery);
}

function initialize_rack_unit_height_quote_only ()
{
	// IF RACKMOUNT UNIT HEIGHT SELECT IS AVAILABLE, BIND IT SO THAT WHEN IT CHANGES
	// CHECK IF IT'S 11-20 UNITS. IF SO, ONLY SHOW CALL TO ORDER FORM. OTHERWISE, SHOW PRODUCT INFO.
	if (jQuery('#RackUnitHeightContOuter select:not(.quote_initialized)').length > 0)
	{
		jQuery('#RackUnitHeightContOuter select').addClass('quote_initialized').change(function() {
			var selected_html = jQuery(this).find(':selected').html();
			if (selected_html.search('click for quote') >= 0)
			{
				show_dynamic_quote_only_form();
				jQuery(this).get(0).selectedIndex = 0;
			}
		});
	}
}

function check_if_ios ()
{
	var is_ios = false;
	(function($) {
		if ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1))
		{
			is_ios = true;
		}
	})(jQuery);
	return is_ios;
}

jQuery(document).ready(function($) {

	// BIND ALL PDF LINKS TO GOOGLE ANALYTICS TRACKING
	track_pdfs();

	initialize_rack_unit_height_quote_only();
	
	// DO TOOL TIPS
	$(".hasTipTip").tipTip(
		{
			'delay'	:	200,
			'edgeOffset'	:	15,
			'defaultPosition'	:	'top'
		}
	);

	/*
	if ($('#product_addtocart_form')){
		var prodForm = $('#product_addtocart_form').serialize();
		setTimeout(
		function(){
			$.ajax({
				url:$('#product_addtocart_form').attr('action'),
				type:'POST',
				success:function(tr){
				}
			});
		},10000);
	}
	*/
    
    // MAIN NAV HOVER
    
    // HIDE NEXT LINE IF THERE IS A SELECTED ITEM
    $('#home-content-header .navActItem').addClass('noLine').next().addClass('noLine');
    
    // ALLOW HOVER
    $('#home-content-header li').hover(
    	function()
	   	{
	    	// OVER
	    	if (!$(this).hasClass('act'+$(this).attr('rel')))
	    	{
	    		$(this).addClass('hover'+$(this).attr('rel'));
	    		//$(this).next().addClass('noLine');
	    	}
	    },
	    function ()
	    {
	    	// OUT
	    	if (!$(this).hasClass('act'+$(this).attr('rel')))
	    	{
	    		$(this).removeClass('hover'+$(this).attr('rel'));
	    		//$(this).next().removeClass('noLine');
	    	}
	    }
	);
    
    
	// facilities page
	jQuery('#carGpCont').jcarousel({scroll:1});
	jQuery('#carklamCont').jcarousel({scroll:1});
        if ($('#carklamCont').length){
            $('.imgGallThumb').click(function(){
                    var thisSrc = $(this).attr('rel');
                    $('#image').animate({opacity:0},350,function(){
                            $('#image').attr('src',thisSrc);
                            $('#image').animate({opacity:1},350);
                    });
                $('.product-image a').attr('href',thisSrc);
            });
    
            $('.imgGallThumb2').click(function(){
                    var thisSrc = $(this).attr('rel');
                    $('#image2').animate({opacity:0},350,function(){
                            $('#image2').attr('src',thisSrc);
                            $('#image2').animate({opacity:1},350);
                    });
                    $('.product-image a').attr('href',thisSrc);
            });
        }

    // sliders    
    jQuery("#Slider1,#Slider2,#Slider3").slider({
        from: 0,
        to: 8,
        step: 1,
        limits:false,
        importance: '&nbsp;',
        scale: ['Low', '|', '|', '|', 'Med', '|', '|', '|','High'],
        skin: "round_plastic"
    });
	
	// validate contact us form
    if(jQuery('#contact_us_form').length){
    	jQuery('#contact_us_form').submit(function(){
    		if(validate_form('#contact_us_form')){
                // SEND THE QUOTE REQUEST 
                    $.ajax({
                      url: '/ecsmail/sendemail/sendContact',
                      type:'POST',
                      data:$('#contact_us_form').serialize(),
                      success:function(data){
                        if (data.search('emailSent')){
                            $.fancybox({'padding':0,'content':"<div style='padding:10px; width:250px; font-size:12px;'><strong>Thank you for your message!<br />We will get back to you as soon as possible.</strong><br /><br /><em>You are being redirected.</em></div>",'onComplete':function(){location.href=location.href}}); 
                        }
                      }
                    }); 
    		}
    		return false;
    	});
    }
    
    // validate case selection form
    if(jQuery('#case-selection-form').length) {
    	jQuery('#case-selection-form').submit(function(){
    		if(validate_form('#case-selection-form')){

                // SEND THE QUOTE REQUEST 
                    $.ajax({
                      url: '/ecsmail/sendemail/sendQuote',
                      type:'POST',
                      data:$('#case-selection-form').serialize(),
                      success:function(data){
                        if (data.search('emailSent')){
                            $.fancybox({'padding':0,'content':"<div style=' padding:10px; width:250px; font-size:12px;'><strong>Thank you for your inquiry!<br />We will respond within 1 business day.</strong><br /><br /><em>You are being redirected.</em></div>",'onComplete':function(){location.href=location.href}});
                        }
                      }
                      
                    });    
    		}
    		return false;
    	});
    }
    
    // validate newsletter sign-up form
    if(jQuery('#newsletter_form').length) {
    	jQuery('#newsletter_form').submit(function(){
    		if(validate_form('#newsletter_form')){
                    
                    // SEND THE QUOTE REQUEST 
                    $.ajax({
                          url: '/ecsmail/sendemail/sendNewsletter',
                          type:'POST',
                          data:$('#newsletter_form').serialize(),
                          success:function(data){
                            if (data.search('emailSent')){
                                $.fancybox({'padding':0,'content':"<div style='padding:10px; width:250px; font-size:12px;'><strong>You have subscribed!</strong><br /><br />Thank you!</div>",'onComplete':function(){location.href=location.href}});
                            }
                          }
                        });
                    }
                    
    			
                
    		return false;
    	});
    }
    
    // validate mini contact form
    if(jQuery('#mini_contact_form').length) {
    	jQuery('#mini_contact_form').submit(function(){
    		if(validate_form('#mini_contact_form')){
                    
                    // SEND THE QUOTE REQUEST 
                    $.ajax({
                          url: '/ecsmail/sendemail/sendMiniContact',
                          type:'POST',
                          data:$('#mini_contact_form').serialize(),
                          success:function(data){
                            if (data.search('emailSent')){
                                $.fancybox({'padding':0,'content':"<div style='color:#000; padding:10px; width:250px; font-size:12px;'><strong>Thank You!</strong><br />We will contact you soon.</div>",'onComplete':function(){location.href=location.href}});
                            }
                          }
                        });
                    }
                    
    			
                
    		return false;
    	});
    }
    
    // quote form
    initialize_quote_form();

	var formError;
	$('#quote-submit').click(function(){
		formError = false;
		$('#quote-product-form input,#quote-product-form textarea').each(function(){
			if($(this).val()=='' || $(this).val()==null){
				$(this).addClass('formErr');
				formError = true;
			}else{
				$(this).removeClass('formErr');
			}
		})
    });
	if(formError==false){
	}
	
	if(jQuery('#home_hero_container').length>0){
		jQuery.preLoadImages('/media/img/home/Home-Hero-ER.jpg','/media/img/home/Home-Hero-Tech.jpg','/media/img/home/Home-Hero-Outdoor.jpg','/media/img/home/Home-Hero-Sound.jpg','/media/img/home/Home-Hero-Military.jpg');
		
		//jQuery('#navMilitary').addClass('navMilitaryAct');
		jQuery('#home_hero_container').attr('rel', 'Military');
		
		jQuery('#home-content-header li').mouseenter(function(){
			
			var current_section = $('#home_hero_container').attr('rel');
			var this_section = $(this).attr('rel');
		
			if (current_section != this_section)
			{
				
				$('#home_hero_container').attr('rel', this_section);
				
				$('#home_hero_container .hero_image_'+current_section).fadeOut(300);
				$('#home_hero_container .hero_image_'+this_section).fadeIn(300);
			}
			
		});
	}
	
	/* OLD HOME HERO
	if(jQuery('#HomeHero').length>0){
		jQuery.preLoadImages('/media/img/home/Home-Hero-ER.jpg','/media/img/home/Home-Hero-Tech.jpg','/media/img/home/Home-Hero-Outdoor.jpg','/media/img/home/Home-Hero-Sound.jpg','/media/img/home/Home-Hero-Military.jpg');
		jQuery('#navMilitary').addClass('navMilitaryAct');
		jQuery('#home-content-header li').mouseenter(function(){
		
			if ($('#HomeHeroImg').attr('alt') != $(this).attr('rel'))
			{
				var tmp_name = $(this).attr('rel');
				var tmp_link = $(this).find('a:eq(0)').attr('href');
				
				$('#HomeHeroLink').fadeOut(300, function() {
					$('#HomeHeroLink').attr('href', tmp_link);
					$('#HomeHeroImg').attr('src', '/media/img/home/Home-Hero-'+tmp_name+'.jpg').attr('alt', tmp_name);
					$(this).fadeIn(300);
				});
			}
			
		});
	}
	*/
        
        // -------------------------------------- VIDEOS PAGE

        if ($('#vidPageContAll').length > 0){
            
            if (check_if_ios() === true)
            {
            	$('#vidPageContAll a').click(function(){
            		var video = $(this).attr('rel');
            		video = video.replace('.flv', '.mp4');
            		var path = "/media/video/mp4_converted_for_web/"+video;
            		var html = '<video width="640" height="360" controls autoplay><source src="'+path+'" type="video/mp4"></source></video>';
            		$('#vid640x424Cont').html(html);
            		var thisCaption = $(this).attr('title');
	                $('#vidPageCaption').html(thisCaption);
            	});
            	
            	$('#vid640x424Cont').html('<video width="640" height="360" controls autoplay><source src="/media/video/mp4_converted_for_web/why_a_case.mp4" type="video/mp4"></source></video>');
            }
            else
            {
	            // video embed
	            var flashvars = {'playbackSource':'theDifference.flv'};
	            var params = {};
	            params.wmode = "transparent";
	            params.allowFullScreen= true;
	            params.scale="noscale"
	            params.align="TL";
	            params.allowScriptAccess="always";
	            var attributes = {};
	            swfobject.embedSWF("/media/video/videoPlayer_640x360.swf", "vid640x360", "640", "360", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	            
	            $('#vidPageContAll a').click(function(){
	                var thisFlashVars = $(this).attr('rel');
	                var thisCaption = $(this).attr('title');
	                $('#vidPageCaption').html(thisCaption);
	                var randomnumber = Math.floor(Math.random()*100)
	    
	                var flashvars = {'playbackSource':thisFlashVars};
	                var params = {};
	                params.wmode = "transparent";
	                params.allowFullScreen= true;
	                params.scale="scale"
	                params.align="TL";
	                params.allowScriptAccess="always";
	                var attributes = {};
	                swfobject.embedSWF("/media/video/videoPlayer_640x360.swf?"+randomnumber, "vid640x360", "640", "360", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	            });
	        }
        }
        
        // -------------------------------------- end VIDEOS PAGE
        
        
        // -------------------------------------- 360's PAGE

        if ($('#page360sContAll').length > 0){
            
            // 360 embed
            /*   
            $('#page360sCaption').html('Initial Title');   
               
           	var thisFlashVars = "assetFolder=/media/prod360/footlocker-large/&hiResAssetSrc=/media/prod360/footlocker-large/&frameCt=36";
            var flashvars = false;
            var params = {flashvars:thisFlashVars};
            params.wmode = "transparent";
            params.allowFullScreen= true;
            params.scale="scale"
            params.align="TL";
            params.allowScriptAccess="always";
            var attributes = {};
            swfobject.embedSWF("/media/prod360/viewer.swf", "page360s640x360", "640", "360", "9.0.0","expressInstall.swf", flashvars, params, attributes);
            */
            
            $('#page360sContAll a').click(function(){
                var thisFlashVars = $(this).attr('rel');
                var thisCaption = $(this).find('img').attr('alt')+' <span class="smaller">(<a href="'+$(this).attr('href')+'">More info</a>)</span>';
                $('#page360sCaption').html(thisCaption);
                var randomnumber = Math.floor(Math.random()*100);
                
                var flashvars = false;
	            var params = {flashvars:thisFlashVars};
	            params.wmode = "transparent";
	            params.allowFullScreen= true;
	            params.scale="scale"
	            params.align="TL";
	            params.allowScriptAccess="always";
	            var attributes = {};
	            swfobject.embedSWF("/media/prod360/viewer.swf", "page360s640x360", "640", "360", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	            
	            return false;
            });




            
            $(document).ready(function() {
            	$('#page360sContAll a:eq(0)').click();
            });
        }
        
        // -------------------------------------- end 360's PAGE
        
        

	
        if ($('#hpInPageVid').length > 0 && check_if_ios() == true)
        {
        	var html = '<video width="217" height="152" poster="/media/img/tryp/qualityCases.jpg" controls><source src="/media/video/mp4_converted_for_web/why_a_case_cropped_homepage.mp4" type="video/mp4"></source></video>';
        	$('#hpInPageVid').html(html);
        	$('#hp-flash-image').remove();
        }
        
        if ($('#catHdrVidPlayer')){
            var vidPlayBackSource = $('#catHdrVidPlayer').attr('rel');
            var flashvars = {
                'playbackSource':vidPlayBackSource,
                'posterFrame':'cat-vid-thumb'
                };
            var params = {};
            params.wmode = "transparent";
            params.allowFullScreen= true;
            params.scale="noscale"
            params.align="TL";
            params.allowScriptAccess="always";
            var attributes = {};
            swfobject.embedSWF("/media/video/videoPlayer_210x118.swf", "catHdrVidPlayer", "210", "147", "9.0.0","expressInstall.swf", flashvars, params, attributes);

            
        }
        

		// Rackmount - Show ajax updater and show standard select
		
		
		
		if (jQuery('.ConfigurableProductSelectDD').length > 0)
		{
			// shove the loader next to select and hide by default
			var new_loader = jQuery('<img id="configurable_loader" style="display:none; margin-left:10px;" src="/media/img/loader_fff_16_16.gif" />');
			
			$(new_loader).insertAfter(jQuery('.ConfigurableProductSelectDD'));
			
			// bind click to trigger blur event for 
				jQuery('.ConfigurableProductSelectDD').change(function(){
					
					if (jQuery(this).val()=='') {
						jQuery('#configurable_loader').hide(0);
						
					}
					else {
						jQuery('#configurable_loader').show(0);
					}
					jQuery(this).focus().blur();
				});
			
			// assign the product name to variable to search
			var prodName = $('.product-name h1').html();
		}

		// CONFIGURABLE SIZES - Lightbox Selection
		if (jQuery('.replaceConfigurableProductSelect').length>0)
		{
			// assign the product name to variable to search
			var prodName = $('.product-name h1').html();
			
			var select_to_replace = $('.replaceConfigurableProductSelect:eq(0)');	
			
			// 1) prep drop downs to have more info
			$(select_to_replace).find('option').each(function() {
			
				var info = configurableProductOptionParseFromRaw(this);
				
				// IF IT ISN'T EQUAL TO "Choose an Option..."
				if (info !== false)
				{
					$(this).html(info['text_to_set']);
				}
				
			});
			
			// 2) change out drop down with button
		
			var select_to_replace_id = $(select_to_replace).attr('id');
			var select_to_replace_container = $('#'+select_to_replace_id+'_container');
			
			var button_caption = $(select_to_replace_container).attr('button_caption');
			
			if (button_caption == '' || button_caption == undefined)
			{
				button_caption = 'Click to Change Size';
			}
			
			// standard button value
			var new_button = $('<input type="button" id="selectSize" value="Select a Size" />');





			// SET CUSTOM BUTTONS TEXT FOR POP-UP CONFIGURABLE PRODUCTS ------------------------------- 

			// if printer
			if (prodName.search(/printer/i)!=-1) {
				new_button = $('<input type="button" id="selectSize" value="Select Printer Type" />');
			}
			// if rifle cases
			if (prodName.search(/rifle cases/i)!=-1) {
				new_button = $('<input type="button" id="selectSize" value="Choose Rifle Case" />');
			}
			
			// end SET CUSTOM BUTTONS TEXT FOR POP-UP CONFIGURABLE PRODUCTS -------------------------------
			
			
			
			
			var new_loader = $('<img id="configurable_loader" style="display:none; margin-left:10px;" src="/media/img/loader_fff_16_16.gif" />');
			
			$(new_button).click(function() {
				
				var current_val = $(select_to_replace).val();
				
				var tmp_content = $('<div>');
            	
            	var tmp_table = $('<table class="fancybox_radio_option_table">');
            	$(tmp_table).append('<tbody>');
            	$(tmp_table).find('tbody').append('<tr class="header">');
            	
            	var initial_row = 1;
            	var table_type;
            
            	// GRAB EACH RADIO, AND RECREATE INSIDE A TABLE
            	$(select_to_replace).find('option').each(function() {
					var existing_option = this;

					var info = configurableProductOptionParseFromParsed(existing_option);
            		
            		if (info === false)
            		{
            			return "next-iteration-this-could-say-anything-except-false";
            		}
            		
            		if (initial_row == 1)
            		{
            			initial_row = 0;
            			if (info['type'] != undefined)
            			{
            				table_type = 'type';
            				$(tmp_table).find('tbody tr:eq(0)').html('<td class="option">&nbsp;</td><td class="type">Type</td><!--<td class="weight">Weight</td>--><td class="price">Price</td>');
            			}
            			else
            			{
            				table_type = 'outside_inside';
            				$(tmp_table).find('tbody tr:eq(0)').html('<td class="option">&nbsp;</td><td class="outside">Outside Dimensions</td><td class="inside">Inside Dimensions</td><!--<td class="weight">Weight</td>--><td class="price">Price</td>');
            			}
            		}
            		
            		var display_text = getDisplayTextFromInfoArray(info);
            		
            		var checked_string = '';
            		
            		if (current_val == $(existing_option).val())
            		{
            			checked_string = ' checked="checked" ';
            		}
            		
            		var new_tr = $('<tr>');
            		
            		if (table_type == 'type')
            		{
            			$(new_tr).html('<td class="option"><input type="radio" '+checked_string+' value="'+$(existing_option).val()+'" name="dupe_'+$(select_to_replace).attr('name')+'" onclick="makeOptionSelected(\''+select_to_replace_id+'\', this.value, \''+escape(display_text)+'\');"></td><td class="type">'+info['type']+'</td><!--<td class="weight">'+info['weight']+'</td>--><td class="price">'+info['price']+'</td>');
            		}
            		else
            		{
            			$(new_tr).html('<td class="option"><input type="radio" '+checked_string+' value="'+$(existing_option).val()+'" name="dupe_'+$(select_to_replace).attr('name')+'" onclick="makeOptionSelected(\''+select_to_replace_id+'\', this.value, \''+escape(display_text)+'\');"></td><td class="outside">'+info['outside']+'</td><td class="inside">'+info['inside']+'</td><!--<td class="weight">'+info['weight']+'</td>--><td class="price">'+info['price']+'</td>');
            		}
            		$(tmp_table).find('tbody').append(new_tr);
            	});
            
            	$(tmp_content).append(tmp_table);
		
		
		// if printer pop-up
		var choiceInstr = 'Choose a Size L x W x H for';

		// SET CUSTOM DIALOG FOR POP-UP DIRECTIVE MESSAGE ------------------------------- 

if ($('.product-name h1').html().search(/Rifle Cases/i)!=-1) {
	choiceInstr = 'Select Size';
}
		if ($('.product-name h1').html().search(/Printer/i)!=-1) {
			choiceInstr = 'Select Printer Type';
		}
		if ($('.product-name h1').html().search(/M9/i)!=-1) {
			choiceInstr = 'Select Size';
		}
		
		// end SET CUSTOM DIALOG FOR POP-UP DIRECTIVE MESSAGE ------------------------------- 
		 
                $.fancybox({
	                'padding':10,
	                'width':500,
	                'height':650,
					'centerOnScroll':true,
	                'autoDimensions':false,
	                'content':"<div class='fancybox_radio_options_title'>"+choiceInstr+": \""+$('#mediaContAll .product-name h1').html()+"\"</div>"+$(tmp_content).html(),
	                'scrolling':'auto',
	                'onComplete':function() {
	                	// FIND INDEX OF ACTUAL SELECTED OPTION AND SET THE FANCYBOX VERSION TO THAT
	                	var tmp_index = $('#SelectSizeContOuter input[type="radio"]:checked').index('#SelectSizeContOuter input[type="radio"]');
	                	
	                }
                });
                
                $('#fancybox-content input[type="radio"]').click(function(){
                    $.fancybox.close();
                });
				
				
			});
			
			$(select_to_replace_container).css('height','0px').css('overflow','hidden').after(new_loader).after(new_button);
		}




        

    // cart update
    if ($('#updateCartAct')){
        $('#updateCartAct').click(function(){
            $('#updateCartForm').submit();
        });
    }
    // cart update
    if ($('#cartUpdateShip')){
        $('#cartUpdateShip').click(function(){
            $('#co-shipping-method-form').submit();
        });
    }
    

// end domready enclosure
});

function getDisplayTextFromInfoArray(info)
{
	// IF OUTSIDE AND INSIDE, THEN DO ONE THING
	if (info['outside'] != undefined && info['inside'] != undefined)
	{
		return 'Outside Dimensions: '+info['outside']+'<br />Inside Dimensions: '+info['inside']+'<br />Weight: '+info['weight']+'<br />Price: '+info['price'];
	}
	// OTHERWISE USE TYPE
	else
	{
		return 'You are configuring: '+info['type']+'<br />Weight: '+info['weight']+'<br />Price: '+info['price'];
	}
}

function configurableProductOptionParseFromRaw (option_obj)
{
	var text_original = jQuery(option_obj).html();
	var text_split = text_original;
	
	var return_vals = new Array();
	
	// IF HAS OUTSIDE AND INSIDE
	if (text_original.search('Outside Dimensions') >= 0 && text_original.search('Inside Dimensions') >= 0)
	{
		text_split = text_split.replace(/Outside Dimensions\: /g, "");
		text_split = text_split.replace(/ Inside Dimensions\: /g, "splithere");
		text_split = text_split.replace(/\: \$/g, "splithere$");
		text_split = text_split.replace(/\: /g, "splithere");
		
		var new_split_array = text_split.split('splithere');
		
		return_vals['outside'] = new_split_array[0];
		return_vals['inside'] = new_split_array[1];
		return_vals['price'] = new_split_array[2];
		return_vals['weight'] = new_split_array[3];
		
		if (return_vals['price'] == undefined)
		{
			return_vals['price'] = '$999.99';
		}
		
		if (return_vals['weight'] == undefined)
		{
			return_vals['weight'] = '123.45 lbs';
		}
		
		return_vals['text_to_set'] = 'outside='+return_vals['outside']+', inside='+return_vals['inside']+', weight='+return_vals['weight']+', price='+return_vals['price'];
		
		if (return_vals['outside'] == 'Choose an Option...')
		{
			return_vals = false;
		}
	}
	// ELSE IS PRINTER CASE
	else
	{
		text_split = text_split.replace(/\: \$/g, "splithere$");
		text_split = text_split.replace(/\: /g, "splithere");
		
		var new_split_array = text_split.split('splithere');
		
		return_vals['type'] = new_split_array[0];
		return_vals['price'] = new_split_array[1];
		return_vals['weight'] = new_split_array[2];
		
		if (return_vals['price'] == undefined)
		{
			return_vals['price'] = '$999.99';
		}
		
		if (return_vals['weight'] == undefined)
		{
			return_vals['weight'] = '123.45 lbs';
		}
		
		return_vals['text_to_set'] = 'type='+return_vals['type']+', weight='+return_vals['weight']+', price='+return_vals['price'];
		
		if (return_vals['type'] == 'Choose an Option...')
		{
			return_vals = false;
		}
	}
	
	return return_vals;
}

function configurableProductOptionParseFromParsed (option_obj)
{
	var text_original = jQuery(option_obj).html();
	var text_split = text_original;

	text_split = text_split.replace(/\, /g, "splithere");
	
	var return_vals = new Array();
	
	var new_split_array = text_split.split('splithere');
	
	for (var i = 0; i < new_split_array.length; i++)
	{
		var tmp_str = new_split_array[i];
		var sub_split = tmp_str.split('=');
		
		return_vals[sub_split[0]] = sub_split[1];
	}
	
	if (text_original == 'Choose an Option...')
	{
		return_vals = false;
	}
	
	return return_vals;
}

function makeOptionSelected(id, value, display)
{
	jQuery('#configurable_loader').show(0);
	jQuery('.btn-cart').hide(0);
	jQuery('#'+id+' [value="'+value+'"]').attr('selected', true);
	jQuery('#'+id).focus().blur();

	jQuery('.current_size_selected').html(unescape(display));
	var unEscapedStr = String(unescape(display));
	
	var remWeightPrice = String(unEscapedStr).replace(/Weight.*/,'');
	
	// if Rackmount (or plug others), don't show the weight and height values 
	if (jQuery('.product-name h1').html().search(/rackmount/i)) {
		jQuery('.current_size_selected').html(remWeightPrice);
	}
}

function makeRadioChecked(name, value, display)
{
	if (jQuery('#SelectSizeContOuter input[type="radio"][name="'+name+'"][value="'+value+'"]').length >= 1)
	{
		
		
		// select a size button by default
		// jQuery('#SelectSizeButton').val('Select a Size');
		
		// if printer
		if (jQuery('.product-name h1').html().search(/printer/i)) {
		//	jQuery('#SelectSizeButton').val('Select Printer Type');
		}

		
		if (!jQuery('#SelectSizeButton').prev().hasClass('current_size_selected'))
		{
			jQuery('#SelectSizeButton').before('<div class="current_size_selected"></div>');
		}
		
		jQuery('#SelectSizeButton').prev().html(unescape(display));
	}
	else
	{
		
		jQuery('#SelectSizeButton').val('Select a Size');
		
		// if printer
		if (jQuery('.product-name h1').html().search(/printer/i)!=-1) {
			jQuery('#SelectSizeButton').val('Select Printer Type');
		}
	}
	jQuery('#SelectSizeContOuter input[type="radio"]').attr('checked', false);
	jQuery('#SelectSizeContOuter input[type="radio"][name="'+name+'"][value="'+value+'"]').attr('checked', true);
}
function ga_track_general(category, action, name)
{
		_gaq.push(['_trackEvent', category, action, name]);
}
