// JavaScript Document

Cufon.replace('.header p.call_us, .header a.cart, .top_menu a, h1, h2, .blueblock .inner h3, #homepage .content_bottom .section h3', {fontFamily: 'Myriad Pro', hover:'true'});
//
Cufon.replace('.blueblock .h3-left-justified-noreturn', {fontFamily: 'Myriad Pro', hover:'true'});


jQuery.fn.change_price = function(){
			var parent_block = $(this).parents('.inner');
			var value=$(this).val();
			var option_text=$(this).children('option:selected').text()
			var product_fullname = option_text.split(' (')[0];
			var product_abbrevname = value.split('_')[0];
			var platform=value.split('_')[1];
			var price=value.split('_')[2];
		    var productcode=value.split('_')[0] + '_' + platform;
			var cart_url = 'https://store.screentime.com/cart';
			var update = (value.indexOf('_u') >= 0);
			var requires_download = ((update == false) && (product_fullname.indexOf('Win') >= 0) && ((productcode.indexOf('stf') >= 0) || (productcode.indexOf('sb')>= 0)));
			if (product_fullname.indexOf('support') >= 0) {
				requires_download = false;
			}
            //alert('product: ' + product_abbrevname + 'update: '+ update + ' platform: ' + platform + ' price: ' + price + ' productcode: ' + productcode);
			
			parent_block.find('div.prod_support img:not(.'+platform+')').hide();
			parent_block.find('div.prod_support img.'+platform).show();
			if (platform=='macwin') parent_block.find('div.prod_support img').show();
			parent_block.find('small').hide();
			parent_block.find('small.'+platform).show();
			parent_block.find('p.price span').text("$"+price);

			if (update) {
				productcode += '_u';
			}
			//price = '.1';
			switch(productcode)
			{
				// Screentime
				
				case 'stf_mac':
					category = 'stf_mac_activate_trialware';
					break;
				case 'stf_win':
					category = 'stf_win_download';
					break;
	
				case 'stf_macwin':
					category = 'stf_macwin_mixed_delivery';
					break;
	
				case 'stf_mac_u':
					category = 'stf_mac_activate_trialware';
					break;
	
				case 'stf_win_u':
					category = 'stf_win_email_link';
					break;
	
				case 'stf_macwin_u':
					category = 'stf_macwin_u_mixed_delivery';
					break;
					
				//mProjector	
				
				case 'mp_mac':
					category = 'mp_mac_activate_trialware';
					break;

				case 'mp_win':
					category = 'mp_win_activate_trialware';
					break;
	
				case 'mp_macwin':
					category = 'mp_macwin_activate_trialware';
					break;
	
				case 'mp_mac_u':
					category = 'mp_mac_activate_trialware';
					break;
	
				case 'mp_win_u':
					category = 'mp_win_activate_trialware';
					break;
	
				case 'mp_macwin_u':
					category = 'mp_macwin_activate_trialware';
					break;
					
				// bundles
				
				case 'sb_mac':
					category = 'sb_mac_activate_trialware';
					break;

				case 'sb_win':
					category = 'sb_win_mixed_delivery';
					break;
	
				case 'sb_macwin':
					category = 'sb_macwin_mixed_delivery';
					break;
				case 'dev_support':
					category = 'dev_support';
					break;
			}           
									 
			// brian
            // parent_block.find('p.price a.foxycart').attr('href','https://store.screentime.com/cart?name='+escape(product)+'&price='+price);
			
			if (requires_download) {
				cart_url += '?code=' + productcode + '&category=' + category;
			} else if ((update)  && (productcode.indexOf('stf') >= 0) && (platform.indexOf('win') >= 0)) {
				cart_url += '?name=' + escape(product_fullname) + '&price=' + price + '&code=' + productcode + '&category=' + category;	

			} else  {
				cart_url += '?name=' + escape(product_fullname) + '&price=' + price + '&code=' + productcode + '&category=' + category;	

			}
			//alert('cart_url: ' +cart_url);

			parent_block.find('p.price a.foxycart').attr('href',cart_url);
            
};

$(function(){

		$('div.tab:first').show();
		
		$('div.tab ol').each(function(){
			var cur_list=$(this);
			var cur_list_elem = 0;
			cur_list.children('li').each(function(){
				cur_list_elem++;
				var str="<div class='num'>"+cur_list_elem+"</div>";
				$(this).prepend(str);
			});
			
		});
		
		$('a[href*=software/flash-projector/index.html]').click(function(){$('ul.tabs li:first a').click();});

		$('ul.tabs li a').click(function(){
			var cur_tab = $('ul.tabs li a').index(this);
			$('ul.tabs li.active').removeClass('active');
			$(this).parent().addClass('active');
			$('div.tab').hide();
			$('div.tab').eq(cur_tab).show();
		});
		
		$('div.blueblock .inner ol').each(function(){
			var cur_list=$(this);
			var cur_list_elem = 0;
			cur_list.find('li').each(function(){
				cur_list_elem++;
				var str="<span>"+cur_list_elem+"</span>";
				$(this).prepend(str);
			});
		});
		
		$('select.cart').each(function(){
			$(this).change_price();
		});
		$('select.cart').change(function(){
			$(this).change_price();
		});
		
		$('#docs .content_left img').each(function(){
			var max_width=$(this).parents().width();
			var cur_width=$(this).width();
			var cur_height=$(this).height();
			if (cur_width > max_width){
				$(this).width(max_width);
				$(this).height(Math.round(max_width/cur_width*cur_height));
				
			}
		});
		
		var width_right=$('div.content_right').width();
		var width_all=$('div.content_2_cols').width() - 20 - 15;
		var width_left = width_all - width_right;
		$('div.content_left').width(width_left);
		

		$("a[@href]").each(function(){
			var href_str = $(this).attr('href');
			if(href_str.charAt(0) == '#'){
				$(this).attr('href',document.URL.split('#')[0] + href_str);
			};
		});
		
		
});

