$(function(){

caa = new CAA;
	jQuery.validator.messages.required = "";
	jQuery.validator.messages.email = "";
});

CAA = function(){
	this.baseURL = 'http://'+location.hostname;
	this.hasViewed = false;
	this.isFront = false;
	this.bioVisible = false;
	this.topicFeaturedSpeakerTimeout = 8000;
	this.curTopicFeaturedSpeaker = 0;
	this.highlightSpeakerTimeout = 4000;
	this.curHighlightSpeaker = 0;
	this.headlinesPerPanel = 9;
  this.type = type;
	this.section = section;
	this.museo = { src: '/media/Assets/sIFR/museo-sans.swf' };
	this.helvetica = { src: 'media/Assets/sIFR/helvetica-neue-condensed-bold.swf' };
	this.initialize();
}

CAA.prototype = {
	initialize:function(){
		sIFR.activate(this.museo);
		this.skin();
		this.addListeners();
	},

	skin:function(){
		this.setBrowserClass();
		$('.preload.none').removeClass('none')
		$('.MsoNormal').attr('style','');
		$('p.MsoNormal span br').remove();
		this.loadFlash();
		this.dropChooseTopicPreload();
		if(this.isAdmin){
			$('body').addClass('admin');
		}
		switch(this.type){
			case 'frontpage':
				/* remove sifr because of rotation
				sIFR.replace(this.museo, {
  				selector: '.speaker h3',
  				css: '.sIFR-root { color:#312e2d }',
					wmode: 'transparent'
				});
				*/
				sIFR.replace(this.museo, {
  				selector: '.headline h3',
  				css: '.sIFR-root { color:#312e2d }',
					wmode: 'transparent'
				});
				$('.shuffle').shuffle()	;
				$('.spotlights .speaker').removeClass('hide');
				this.highlightSpeakerRevolution()
				setInterval(this.highlightSpeakerRevolution, this.highlightSpeakerTimeout);
				break;
			case 'speaker':
				if($('.teaser').length > 0){
					$('.bio').slideUp(0,function(){ $(this).removeClass('preload')});
				}else{
						sIFR.replace(this.museo, { selector: '.bio h1', css: '.sIFR-root { color:#312e2d }', wmode: 'transparent' 	});
				}
				$('.reviews_full').slideUp(0,function(){ $(this).removeClass('preload')});
				this.formatMediaList();
				this.setRequestInfoFormAsAjax()
				sIFR.replace(this.museo, { selector: '.teaser h1', 	css: '.sIFR-root { color:#312e2d }',	wmode: 'transparent' });
				break;
			case 'speaker_media':
				this.formatMediaList();
				this.setRequestInfoFormAsAjax()
				break;
				sIFR.replace(this.museo, { selector: 'h1',	css: '.sIFR-root { color:#312e2d }',		wmode: 'transparent' });
			case 'speaker_bio':
			case 'speaker_reviews':
				sIFR.replace(this.museo, {			selector: 'h1',			css: '.sIFR-root { color:#312e2d }',		wmode: 'transparent' });
				this.setRequestInfoFormAsAjax()
				break;
			case 'speakers':
				this.formatSpeakersByAlpha();
				break;
			case 'speakers_topic':
				this.formatTopicColumns();
				sIFR.activate(this.helvetica);
				sIFR.replace(this.helvetica, { selector: '#main .mouseout', 	css: '.sIFR-root { color:#740717 }',	wmode: 'transparent' });
				sIFR.replace(this.helvetica, { selector: '.topics .mouseout', 	css: '.sIFR-root { color:#fcfcfc }',	wmode: 'transparent' });
				sIFR.replace(this.helvetica, { selector: '.mouseover', 	css: '.sIFR-root { color:#740717 }',	wmode: 'transparent' })
				break;
			case 'topic':
				this.topicFeaturedSpeakerRevolution();
				this.formatTopicSpeakerColumns();
				setInterval(this.topicFeaturedSpeakerRevolution, this.topicFeaturedSpeakerTimeout);
				this.setRequestInfoFormAsAjax();
				$('#topic .featured_speaker .sifr').css('width',($('#topic .featured_speaker .hd .sifr').text().length*12)+'px');
				$('#topic .last .sifr').css('width', ($('#topic .last .hd .sifr').text().length*12)+'px');
				sIFR.replace(this.museo, { selector: '#topic .featured_speaker .hd .sifr', 	css: '.sIFR-root { color:#ffffff }',	wmode: 'transparent' });				
				sIFR.replace(this.museo, { selector: '#topic .last .hd .sifr', 	css: '.sIFR-root { color:#ffffff }',	wmode: 'transparent' });				
				break;
			case 'headlines':
				sIFR.replace(this.museo, { selector: '.content_block h4', 	css: '.sIFR-root { color:#312e2d }',	wmode: 'transparent' });
				sIFR.replace(this.museo, { selector: '.content_block h3', 	css: '.sIFR-root { color:#312e2d }',	wmode: 'transparent' });	
				this.prepHeadlinesList();
				break;
			case 'search_results':
				this.formatSearchResults();
				break;
			case 'contact':
				this.setContactFormAsAjax()
				$('.thank_you').fadeOut(0).removeClass('preload');
				break;
		}
		this.setSifrOnload();
		this.preloadImages();
	},

	addListeners:function(){
		if(this.loggedIn){
		}else{}
		$('.choose_topic').click(this.toggleDropChooseTopic).attr('href','javascript:void(0)');
		$('body').click(this.closeDropChooseTopic);
		$('#header .topics').mousemove(function(e){caa.stopPropagation(e)}).mouseover(function(e){caa.stopPropagation(e)}).click(function(e){caa.stopPropagation(e)});
		$('form:first a').click(this.submitSearch);
		switch(this.type){
			case 'frontpage':
				$('.headline').mouseover(function(){ $(this).find('.hover').removeClass('none')}).mouseout(function(){ $(this).find('.hover').addClass('none')});
				break;
			case 'speaker':
				$('.teaser .btn').click(this.revealBio).attr('href','javascript:void(0)');
				$('.reviews a').click(this.revealReviews).attr('href','javascript:void(0)');
				$('.bio .btn').click(this.hideBio);
				$('.reviews_full a').click(this.hideReviews);
				$('.media a').mouseover(this.toggleMediaTitle).mouseout(this.toggleMediaTitle);
				$('#related_content input ').focus(function(){
					var t = $(this);
					if(t.val() == t.attr('initial')) t.val('');
				})
				$('#related_content input').blur(function(){
					var t = $(this);
					if(t.val() == '') t.val(t.attr('initial'));
				})	;
				break;
			case 'topic':
			case 'speaker_bio':
			case 'speaker_reviews':
				$('#related_content input').focus(function(){
					var t = $(this);
					if(t.val() == t.attr('initial')) t.val('');
				})
				$('#related_content input').blur(function(){
					var t = $(this);
					if(t.val() == '') t.val(t.attr('initial'));
				})	;
				break;
			case 'speaker_media':
				$('.media a').mouseover(this.toggleMediaTitle).mouseout(this.toggleMediaTitle);
				$('#related_content input').focus(function(){
					var t = $(this);
					if(t.val() == t.attr('initial')) t.val('');
				})
				$('#related_content input').blur(function(){
					var t = $(this);
					if(t.val() == '') t.val(t.attr('initial'));
				})	;
				break;
			case 'speakers_topic':
				$('.topics a').mouseover(this.sifrMouseover).mouseout(this.sifrMouseout)
				break;
			case 'headlines':
				$('#main .navigation a').click(this.slideHeadlinesPanel);
				$('.content_block .content').mouseover(function(){ $(this).find('.hover').removeClass('none')}).mouseout(function(){ $(this).find('.hover').addClass('none')});
				break;
			case 'search_results':
				$('.content_block .content').mouseover(function(){ $(this).find('.hover').removeClass('none')}).mouseout(function(){ $(this).find('.hover').addClass('none')});
				break;
			case 'contact':
				$('#main input').focus(function(){
					var t = $(this);
					if(t.val() == t.attr('initial')) t.val('');
				})
				$('#main input').blur(function(){
					var t = $(this);
					if(t.val() == '') t.val(t.attr('initial'));
				})	;
				$('.reset').click(function(){ $(this).parents('form').get(0).reset() });
				break;
		}
		
		$('.unbind').unbind();
	},
	
	setSifrOnload:function(){
		window.onload = function(){
			$('object, embed').each(function(){
				var t = $(this).parent().removeClass('sifr').end();
				if(caa.type == 'speakers_topic'){
					t.parents('h4').children().width(t.attr('width')+'px');
					if($.browser.msie){
						t.parents('li').height(t.attr('height')+'px').children().width(t.attr('width')+'px');
					}else{
						t.parents('li').height('35px').children().width(t.attr('width')+'px');	
					}
				}else{
					t.parent().width(t.attr('width')+'px');
				}
			}) ;
		}
	},
	
	sifrMouseover:function(e){
		e.stopPropagation();
		var p = $(this).parent();
		p.find('.mouseout').addClass('preload')
		p.find('.mouseover').removeClass('preload');
	},

	sifrMouseout:function(e){
		e.stopPropagation();
		var p = $(this).parent();
		p.find('.mouseover').addClass('preload')
		p.find('.mouseout').removeClass('preload');
	},

	sifrLinkReady:function(selector){
		$(selector).removeClass('sifr');

	},
	
	setRequestInfoFormAsAjax:function(){
		var options = { 
		 	form: 				$('#related_content form'),
      beforeSubmit: this.validateInfoForm,
      success:      this.infoFormResponse,
			resetForm: 		true
    }; 
		options.form.find('.btn').click(function(){options.form.submit()}).end()
		.ajaxForm(options).validate({
			rules: {
			full: { requiredNotDefault:true },
			email: {
  	    	required: true,
    			email: true
    		}
			},
			debug:true
		});		
		
	},
	
	validateInfoForm:function(){
		return this.form.valid();
	},
	
	infoFormResponse:function(){
		var c = $('#comments');
		c.text(c.attr('response'));
		setTimeout(function(){ $('#comments').text('')},3000);
	},


	setContactFormAsAjax:function(){
		var options = { 
		 	form: 				$('#main form'),
      beforeSubmit: this.validateContactForm,
      success:      this.contactFormResponse,
			resetForm: 		true
    }; 
		options.form.find('.submit').click(function(){options.form.submit()	}).end()
		.ajaxForm(options).validate({
			rules: {
			first: { requiredNotDefault:true },
			last: { requiredNotDefault:true },
			email: {
  	    	required: true,
    			email: true
    	},
    	phone: {
      	required: true,
      	phoneUS: true
    	}
		},
			debug:true
		});		
		
	},
	
	validateContactForm:function(data){
		return this.form.valid();
	},
	
	contactFormResponse:function(){
		$('.thank_you').fadeIn(400,function(){ $(this).fadeOut(4000) });
	},


	toggleDropChooseTopic:function(e){
		e.stopPropagation();
		$('.find .topics ul li.empty').remove();
		var p = $(this).blur().parent();
		if(p.is('.on')){
			p.removeClass('on');
			$('#header .topics').slideUp(400);
		}else{
			p.addClass('on');
			$('#header .topics').slideDown(400);			
		}
		return false;
	},

	closeDropChooseTopic:function(e){
		e.stopPropagation();
		var p = $('.choose_topic').parent();
		if(p.is('.on')){
			p.removeClass('on');
			$('#header .topics').slideUp(400);	
		}
	},
	
	dropChooseTopicPreload:function(){
		var topics = $('.find .topics ul:eq(0) li');
		var t,p;
	  var numPerCol = Math.round(topics.length / 3);
		var secondCol = $('.find .topics ul:eq(1)')
		var thirdCol = $('.find .topics ul:eq(2)');
		topics.each(function(i){
			t = $(this);
			if(i >= (2*numPerCol)){
				t.remove().appendTo(thirdCol);
			}else if( i >= numPerCol) {
				t.remove().appendTo(secondCol);
			}
		}).ready( function(){
			if($('.find .topics ul.second').find('a:first').not('.parent')){
				p = $('.find .topics ul.second a').index($('.find .topics ul.second').find('a.parent:first'));
				$('.find .topics ul.second a:lt('+p+')').parent().remove().appendTo($('.find .topics ul:first'));
			}
		
			if($('.find .topics ul.third').find('a:first').not('.parent')){
				p = $('.find .topics ul.third a').index($('.find .topics ul.third').find('a.parent:first'));
				$('.find .topics ul.third a:lt('+p+')').parent().remove().appendTo($('.find .topics ul.second'));
			}
			$('#header .topics .shadowWrap').width($('#header .topics .contentWrap').width()+10).height($('#header .topics .contentWrap').height()-parseInt($('#header .topics .shadowWrap').css('top')))
			$('#header .topics .bottom').css('top',$('#header .topics .contentWrap').height());
		}).ready(function(){
			$('#header .topics').height($('#header .topics .contentWrap').height()+parseInt($('#header .topics .shadowWrap').css('top'))).slideUp(0, function(){$(this).removeClass('preload').addClass('postload') });	
		});
	},

	topicFeaturedSpeakerRevolution:function(){
		var c = (typeof(caa) != 'undefined') ? caa : this;; 
		var f = $('.featured_speaker a').css('display','none');
		var visible = c.curTopicFeaturedSpeaker + 1;
		c.curTopicFeaturedSpeaker = (visible > (f.length-1)) ? 0 : visible;
		f.eq(c.curTopicFeaturedSpeaker).css('display','block');
		/* had to remove sifr because of rotation
		sIFR.replace(this.museo, { selector: 'h2', 	css: '.sIFR-root { color:#312e2d }',	wmode: 'transparent' });
		$('object, embed').each(function(){
			var t = $(this).parent().removeClass('sifr').removeClass('preload').end();
			t.parents('.header').children().width(t.attr('width')+'px');
		}) ;
		*/
	},

	highlightSpeakerRevolution:function(){
		var c = (typeof(caa) != 'undefined') ? caa : this;; 
		var f = $('.spotlights .speaker').css('display','none');
		var visible = c.curHighlightSpeaker + 1;
		c.curHighlightSpeaker = (visible > (f.length-1)) ? 0 : visible;
		f.eq(c.curHighlightSpeaker).css('display','block');
	},

	toggleMediaTitle:function(e){
		e.stopPropagation();
		if(caa.bioVisible) return;
		var h5 = $(this).parent().find('h5:first');
		if(h5.is('.none'))	h5.removeClass('none');
		else $('h5').addClass('none');
	},
	
	formatMediaList:function(){
		var t,h;
		var l = $('.media li');
		var r = l.length % 5;
		l.each(function(i){
			t = $(this);
			h = t.height();
			if(((i+1) %  5) == 0) t.addClass('last');
		})
		
		//.parent().height((r*h)+'px');
		$('.media').slideUp(0,function(){ $(this).slideDown(0).removeClass('preload') })
	},
	
	prepHeadlinesList:function(){
		$('.view_port').addClass('withScript');
		var headlines = $('.view_port .panels ul:first li');
		if(headlines.length < (this.headlinesPerPanel+1)){
			$('.view_port .panels ul').removeClass('none');
			$('.view_port .panels ul').each(function(){
				$(this).removeClass('none').children().each(function(i){
					if((i+1) % 3 == 0) $(this).addClass('left');
				});
			});
			return;
		}
		var numPanels = Math.round(headlines.length / this.headlinesPerPanel);
		if((headlines.length % this.headlinesPerPanel) != 0) numPanels++;

		for(	var i = 1; i < numPanels; i++){
			$('ul.template').clone().removeClass('template').insertAfter($('.view_port .panels ul:first'));
		}
		$('ul.template').remove();
		for(	i = numPanels-1; i > 0; i--){
			$('.view_port .panels ul:first li:gt('+ ((this.headlinesPerPanel*i)-1) +')').remove().appendTo( $('.view_port .panels ul:eq('+i+')') );
		}
		$('.view_port .panels').width($('.view_port .panels ul').width()*numPanels);

		$('.view_port .panels ul').each(function(){
			$(this).removeClass('none').children().each(function(i){
				if((i+1) % 3 == 0) $(this).addClass('left');
			});
		});
		$('.navigation').removeClass('none');

	},
	
	slideHeadlinesPanel:function(e){
		e.stopPropagation();
		var p = $('.view_port .panels');
		var n = $('.view_port .panels ul').length;
		var w = $('.view_port').width();
		var cur = parseInt(p.attr('curpanel'));
		if($(this).parents('.prev').length > 0)	cur--;
		else	cur++;
		var l = 0-(w*cur);
		p.animate({left:l},500);
		p.attr('curpanel',cur)
		caa.resetHeadlinesNav(cur,n)
	},

	resetHeadlinesNav:function(curpanel, numpanels){
		if(curpanel < (numpanels-1)){
			$('.navigation .next div').addClass('none');		
			$('.navigation .next a').removeClass('none');	
		}else{
			$('.navigation .next a').addClass('none');
			$('.navigation .next div').removeClass('none');
		}
		
		if(curpanel > 0){
			$('.navigation .prev div').addClass('none')
			$('.navigation .prev a').removeClass('none');
		}else{
			$('.navigation .prev a').addClass('none');
			$('.navigation .prev div').removeClass('none');
		}
	},
	
	submitSearch:function(e){
		e.stopPropagation();
		$(this).blur();
		if($('#term').val() != '') $('form:first').submit();
	},
	
	formatSearchResults:function(){
		var t,n;
		$('ul.headlines li').each(function(i){
			if((i+1) % 3 == 0) $(this).addClass('left');
		});
		if($('ul.speakers').length > 0){
				$('ul.speakers li').each(function(){
				t = $(this);
				n = $(this).attr('node');
				$("ul.speakers li[node='"+n+"']:gt(0)").remove();
			}).parent().removeClass('none').ready(function(){
				$("#main ul").removeClass('none');
				$('#xsltsearch_summary .count').text($('#main li').length);
				
			});
		}else{
			$('#main ul').removeClass('none').ready(function(){
				$('#xsltsearch_summary .count').text($('#main li').length);
			});
		}
	},
	
	
	revealBio:function(e){
		e.stopPropagation();
		caa.bioVisible = true;
		window.scrollTo(0,0);
		var rf = $('.reviews_full');
		if(rf.length > 0 && rf.css('display') == 'block') $('.reviews_full').slideUp(0);
		if($.browser.msie){
			$('.media ul, .teaser .content, .bio .innerContent').addClass('hidden');
		}
		$('.teaser,.media,.reviews,.speeches').slideUp(500, function(){$('.bio').slideDown(500, function(){ $('.bio .innerContent').removeClass('hidden'); 	sIFR.replace(caa.museo, { selector: '.bio h1', css: '.sIFR-root { color:#312e2d }', wmode: 'transparent' 	}) })});
		pageTracker._trackPageview(window.location.pathname+'/DHTMLBioFull');
	},
	
	hideBio:function(e){
		e.stopPropagation();
		caa.bioVisible = false;		
		$('.bio .innerContent').addClass('hidden');
		$('.bio').slideUp(500, function(){
			$('.teaser,.media,.reviews,.speeches').slideDown(500, function(){
				if($.browser.msie)	$('.media ul, .teaser .content').removeClass('hidden');
			});
		});
	},	
	
	revealReviews:function(e){
		e.stopPropagation();
		window.scrollTo(0,0);
		if($.browser.msie){ $('.media ul').addClass('hidden')	}
		$('.media,.reviews,.speeches').slideUp(500, function(){	$('.reviews_full').slideDown(500)});
		pageTracker._trackPageview(window.location.pathname+'/DHTMLReviewsFull');
	},
	
	hideReviews:function(e){
		e.stopPropagation();
		$('.reviews_full').slideUp(500, function(){
			$('.media, .reviews,.speeches').slideDown(500, function(){ setTimeout(function(){$('.media ul').removeClass('hidden')},100 ) 	});
		});
	},
	
	formatAlphaColumns:function(){
		var t,c,li, numCols, numPerCol, thirdCol, secondCol;
		$('dd').each(function(){
			d = $(this);
			c = d.find('ul.first li');
		  secondCol = 	d.find('ul.second');
			thirdCol = d.find('ul.third');
			if(c.length > 10){
				numPerCol = Math.round(c.length / 3);
				c.each(function(i){
					if((i+1) > (2*numPerCol)){
						thirdCol.append($(this).remove());
					}else if(( i+1) > numPerCol) {
						secondCol.append($(this).remove());
					}
				});
			}else if(c.length > 5){
				numPerCol = Math.round(c.length / 2);
				c.each(function(i){
					if(( i+1) > numPerCol) {
						secondCol.append($(this).remove());
					}
				});
			}
			//else if(c.length == 0) d.prev().addClass('none').end().addClass('none');
		}).ready(function(){
			$('dd ul').each(function(){ $(this).children(':last').addClass('last')});
			$('dl.speakers_by').removeClass('none');
		});
	},
	
	formatSpeakersByAlpha:function(){
		var letters = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
		var t, l, i;
		var z;
		var caa = this;
		var s = $('.tempSpeakers li').each(function(c){
			z = c;
			t = $(this);
			l = t.attr('lastname').toLowerCase().slice(0,1);
			i = letters.indexOf(l);
			$('dd').eq(i).find('ul:first').append(t.remove());
		}).ready(function(){ caa.formatAlphaColumns() });
	},

	
	formatTopicColumns:function(){
			$('dd').each(function(){
			d = $(this);
			c = d.find('ul.first li');
		  secondCol = 	d.find('ul.second');
			thirdCol = d.find('ul.third');
			if(c.length > 10){
				numPerCol = Math.round(c.length / 3);
				c.each(function(i){
					if((i+1) > (2*numPerCol)){
						thirdCol.append($(this).remove());
					}else if(( i+1) > numPerCol) {
						secondCol.append($(this).remove());
					}
				});
			}else if(c.length > 5){
				numPerCol = Math.round(c.length / 2);
				c.each(function(i){
					if(( i+1) > numPerCol) {
						secondCol.append($(this).remove());
					}
				});
			}else if(c.length == 0) d.prev().remove().end().remove();
		});
		$('dd ul').each(function(){ $(this).children(':last').addClass('last')});
		$('dd ul.second, dd ul.third ').each(function(){ $(this).children(':first').remove() });
	},
	
	formatTopicSpeakerColumns:function(){
		c = $('.speaker_list:first li');
		secondCol = 	$('.speaker_list.second');
		thirdCol = $('.speaker_list.third');
		if(c.length > 10){
			numPerCol = Math.round(c.length / 3);
			c.each(function(i){
				if((i+1) > (2*numPerCol)){
					thirdCol.append($(this).remove());
				}else if(( i+1) > numPerCol) {
					secondCol.append($(this).remove());
				}
			}).ready(function(){ $('.content_block.none').removeClass('none') });
		}else if(c.length > 5){
			numPerCol = Math.round(c.length / 2);
			c.each(function(i){
				if(( i+1) > numPerCol) {
					secondCol.append($(this).remove());
				}
			}).ready(function(){ $('.content_block.none').removeClass('none') })
		}else $('.content_block.none').removeClass('none');

	},
	

	preloadImages:function(){
		var imgs = [];
		var images = this.baseURL + '/images/';
		switch(this.type){
		case 'frontpage':
			imgs.push(images+'bg/macFFBgHack.png');
			break;
		case ' headlines':
			imgs.push(images+'bg/macFFBgHack.png');
			break;
		case 'speaker':
			break;
		case 'topic':
		case 'speaker_reviews':
		case 'speaker_media':
	}
		$.preloadImages(imgs);
	},
	
	setBrowserClass:function(){
		var b;
		if($.browser.mozilla) b = 'mozilla';
		else	if($.browser.msie) b = 'msie';
		else	if($.browser.safari)	b = 'safari';
		else	if($.browser.opera) b = 'opera';
		$('html').addClass(b);
	},

	stopPropagation:function(e){
			e.stopPropagation();
			return false;	
	},


	loadFlash:function(){ 
		var flashvars = {};
    var params = { allowScriptAccess: "always" };
		var attributes = {};
		var w, h, url, id;
		switch(this.type){
			case 'frontpage':
				params.wmode = 'transparent';
			  params.scale = "showall";
				params.width = "913";
				params.height = "423";
				w =  913;
				h =  423;
				url = this.baseURL+"/swf/feature.swf";
				id = "flash";
				break;
			case 'speaker_media':
				params.width = "547";
				params.height = "328";
			  params.scale = "noscale";
				params.allowFullScreen = 'true';
				params.bgcolor = '#E2DDDC';
				params.movie = mediaURL;
				w =  547;
				h =  328;
				url = mediaURL;
				id = "viddler";
				break;
		}
		swfobject.embedSWF(url, id, w, h, "9.0.1",this.baseURL+"/themes/caa/swf/expressInstall.swf", flashvars, params, attributes);
	},

	getMovie:function ( movieName ){
		// IE and Netscape refer to the movie object differently.
		
		// This function returns the appropriate syntax depending on the browser.
		if (navigator.appName.indexOf ("Microsoft") !=-1) {
			return window[movieName];
		}	else {
			return document[movieName];
		}
	},

	setFlashVar:function( movie, name, val ){
		var movie = (typeof movie == 'string') ? this.getMovie(movie) : movie
		if(movie != null && movie.SetVariable) 	movie.SetVariable( name,val);
	}

}

$.preloadImages = function(imgs){
  for(var i = 0; i<imgs.length; i++){
		$("<img>").attr("src", imgs[i]);
  }
}

$.sifrLink = function(selector){
	var t = $(selector);
	var txt = 	t.text();
	t.text().wrap('span').children().addClass('mouseout').end().append('<span class="mouseover sifr"></span>');
	t.find('mouseover').text(txt);

	
}

Array.prototype.indexOf = function(el){
	for (var i = 0; i < this.length; i++) {
		if (this[i] == el) return i;
	}
	return -1;
}

jQuery.validator.addMethod("requiredNotDefault",function(name,element){
	return name != '' && name != $(element).attr('initial');
}, "");

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "");

