font_replace();

$(document).ready(function(){
	notices_ticker();
	load_polls();
	search_box();
	cal();
	//fix_features();
	
})

	function font_replace()
	{
		Cufon.replace('.f_h2')('.features h3');
	}

	function fix_features()
	{
		$('.features .summary').each(function(){
			height = $(this).height();
			$(this).html('My Height Is '+height);
			//if(height>50) alert('found');
		})
	}

/* send to friend */

	function refer_a_friend(url,title)
	{
		page = base_url + 'index.php?template=idl&c=friend&title='+title+'&url='+url
		open_window(page,600,400,'friend');	
	}

/* popup window */

	_w = null;
		
	function open_window(path,width,height,win)
	{
		
		w = window.screen.availWidth;
		h = window.screen.availHeight;	
		
		posL = (w-width)*.5;
		posT = (h-height)*.5;
		
		if(_w && _w.open){
			_w.close();
		}	
		
		_w = window.open(path,win,'width='+width+',height='+height+',top='+posT+',left='+posL+',menubar=0,location=0,toolbar=0,personalbar=0,status=0,scrollbars=1,allowresize=1,dependent=1,resizable=1');
		
	}

/* cal */

	function cal()
	{
		$('.calendar .toggle').click(function(){
			rel = $(this).attr('rel');
			if($(this).hasClass('closed'))
			{
				$(this).removeClass('closed').addClass('open');
				$('#calendar_'+rel+' .small').hide();
				$('#calendar_'+rel+' .big').show();
			}
			else
			{
				$(this).removeClass('open').addClass('closed');
				$('#calendar_'+rel+' .small').show();
				$('#calendar_'+rel+' .big').hide();				
			}
			return false;
		});
		
		$('.calendar .keyword .input').focus(function(){
			if($(this).val()=='calendar search')
				$(this).val('')
			/// alert($(this).val());
		});		
		
	}
	
	function load_cal(sidebar_id)
	{
		var myDate=new Date();
		$('#calendar_'+sidebar_id+' .cal').load(site_url+'events/cal/'+myDate.getFullYear()+'/'+(myDate.getMonth()+1)+'/'+sidebar_id);
	}
	
	function change_month(year,month,sidebar_id)
	{
		$('#calendar_'+sidebar_id+' .cal').load(site_url+'events/cal/'+year+'/'+month+'/'+sidebar_id);
		// createCookie('cal_date','events/cal/'+year+'/'+month,0);
		return false;
	}

/* search */

	function search_box()
	{
		$('.search .input').focus(function(){
			if($(this).val()=='search indesignlive.com')
				$(this).val('')
			/// alert($(this).val());
		});
		$('.search .input').blur(function(){
			// if($(this).val()=='')
				// $(this).val('search indesignlive.com')
		});		
	}

/* polls */

	var poll_ids = new Array();
	var poll_divs = new Array();
	
	function queue_poll(div_id,poll_id)
	{
		poll_ids.push(poll_id);
		poll_divs.push(div_id);
	}
	
	function load_polls()
	{
		for(i=0;i<poll_ids.length;i++)
		{
			//alert(site_url+'poll/'+poll_ids[i]);
			$('#poll_'+poll_divs[i]).load(site_url+'polls/'+poll_ids[i]+'/'+poll_divs[i]);
		}
	}
	
	function load_poll(poll_id,sidebar_id,results)
	{
		$('#poll_'+sidebar_id).load(site_url+'polls/'+poll_id+'/'+sidebar_id+'/'+results);	
		return false;
	}
	
	function vote(poll_id,sidebar_id)
	{
		name = 'poll_'+poll_id+'_'+sidebar_id;
		value = $('input[@name='+name+']:checked').val();
		if(value)
		{
			$.post(site_url+'polls/'+poll_id+'/'+sidebar_id,{answer:value,poll:poll_id},function(data){
				
				$('#poll_'+sidebar_id).fadeOut('slow',function(){
					$(this).html(data).fadeIn('slow');
					/*$(this).load(site_url+'polls/'+poll_id+'/'+sidebar_id+'/results',function(){
						$(this).fadeIn('slow');
					});*/								   
				});				
				
			})

		}
	}

/* news flash */

	var ticker_width = 0;
	
	function notices_ticker()
	{
		
		$('#news-flash ul').hover(function(){
			$(this).stop();
		},function(){
			notices_ticker_animate()
		})
		
		var ticker_mask_width = $('#news-flash div').width();
		//$('#news-flash ul').css({marginLeft:ticker_mask_width});
		$('#news-flash ul').find("li").each(function(){
			ticker_width+=$(this).width()+15; // 15 right padding
		});
		$('#news-flash ul').width(ticker_width).animate({opacity:1},3000,function(){notices_ticker_animate();});
		
	}
	
	function notices_ticker_animate()
	{
		var ticker_margin = $('#news-flash ul').css('margin-left');
		ticker_margin = ticker_margin.replace('px','') * 1;
		$('#news-flash ul').animate({marginLeft:'-=2px'}, 20, 'linear', function(){
			if(ticker_margin < -ticker_width) $(this).css({marginLeft:'780px'});
			notices_ticker_animate()
		});
	}
	
/* sifr */	
/*
	var helvetica_thin = {
		src: assets_url+"assets/idl/v2/swf/helvetica_thin.swf"
	};
	
	sIFR.activate(helvetica_thin);
	
	sIFR.replace(helvetica_thin, {
		selector: '.f_h2',
		wmode: 'transparent',
		css:{ '.sIFR-root': { 'color': '#999999' }}
	});
	
	sIFR.replace(helvetica_thin, {
		selector: '.f_poll',
		wmode: 'transparent',
		css:{ '.sIFR-root': { 'color': '#FFFFFF' }}
	});	
	

	sIFR.replace(helvetica_thin, {
		selector: '.pink_purple .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #bf50f8; text-decoration:none }', 
		'a:link { color: #bf50f8; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});

	sIFR.replace(helvetica_thin, {
		selector: '.dark_purple .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #f171fc; text-decoration:none }', 
		'a:link { color: #f171fc; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});
	
	sIFR.replace(helvetica_thin, {
		selector: '.blue_purple .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #7195fc; text-decoration:none }', 
		'a:link { color: #7195fc; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});
	
	sIFR.replace(helvetica_thin, {
		selector: '.light_green .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #50f8c3; text-decoration:none }', 
		'a:link { color: #50f8c3; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});
	
	sIFR.replace(helvetica_thin, {
		selector: '.dark_green .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #c3fc71; text-decoration:none }', 
		'a:link { color: #c3fc71; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});		
	
	sIFR.replace(helvetica_thin, {
		selector: '.blue .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #00aeef; text-decoration:none }', 
		'a:link { color: #00aeef; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]  		
	});	
	
	sIFR.replace(helvetica_thin, {
		selector: '.red .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #ED1C24; text-decoration:none }', 
		'a:link { color: #ED1C24; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});
	sIFR.replace(helvetica_thin, {
		selector: '.pink .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #EC008C; text-decoration:none }', 
		'a:link { color: #EC008C; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});
	sIFR.replace(helvetica_thin, {
		selector: '.orange .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #ff5400; text-decoration:none }', 
		'a:link { color: #ff5400; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});
	sIFR.replace(helvetica_thin, {
		selector: '.yellow .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #f8c000; text-decoration:none }', 
		'a:link { color: #f8c000; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});
	sIFR.replace(helvetica_thin, {
		selector: '.bright_yellow .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #fff200; text-decoration:none }', 
		'a:link { color: #fff200; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});	
	sIFR.replace(helvetica_thin, {
		selector: '.green .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #41ad49; text-decoration:none }', 
		'a:link { color: #41ad49; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});	
	
	sIFR.replace(helvetica_thin, {
		selector: '.turquoise .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #00b1b2; text-decoration:none }', 
		'a:link { color: #00b1b2; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});	
	
	sIFR.replace(helvetica_thin, {
		selector: '.purple .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #754FA0; text-decoration:none }', 
		'a:link { color: #754FA0; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});	
	
	sIFR.replace(helvetica_thin, {
		selector: '.dark_blue .a_h3', wmode: 'transparent',
		css: [ 
		'a { color: #132694; text-decoration:none }', 
		'a:link { color: #132694; text-decoration:none }', 
		'a:hover { color: #FFFFFF; }' 
		]		
	});		
*/
	
	