function buttonOver(el){
	$(el.parentNode).addClass('button button-over');
}

function buttonDown(el){
	$(el.parentNode).addClass('button button-down');
}

function buttonOut(el){
	$(el.parentNode).removeClass('button-over button-down');
}


function Flash(){this.movie="";this.img="";this.width="";this.height="";this.alt="";this.bgcolor="transparent";this.ver=7;this.link="";this.tracker="";this.ie=((navigator.userAgent.toLowerCase().indexOf("opera")==-1)&&navigator.appName=="Microsoft Internet Explorer")?true:false;this.className="";this.id="";this.urlparam="url";this.target="_blank";this.install=false;this.flashvars=null}
Flash.prototype.iF=function(i){if(!this.ie)return true;try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);return true}catch(e){return false}}
Flash.prototype.write=function(m,w,h,a,b){var o=this.HTML(m,w,h,a,b);document.write(o)}
Flash.prototype.param=function(n,v){return '<param name="'+n+'" value="'+v+'" />';}
Flash.prototype.writeBanner=function(i,w,h,l,t,b){this.preBanner(i,null,w,h,l,t,b);var lnk=(this.link==null||this.link=="")?false:true;this.movie=this.img.slice(0,this.img.lastIndexOf('.'))+".swf"+((lnk)?"?"+this.urlparam+"="+escape(this.link):"");this.write();}
Flash.prototype.writeBannerAlt=function(i,m,w,h,l,t,b){this.preBanner(i,m,w,h,l,t,b);var lnk=(this.link==null||this.link=="")?false:true;if(m!=null&&m!='')this.movie=m+((lnk)?"?"+this.urlparam+"="+escape(this.link):"");this.write();}
Flash.prototype.preBanner=function(i,m,w,h,l,t,b){if(i!=null&&i!="")this.img=i;if(l!=null&&l!="")this.link=l;if(t!=null&&t!="")this.tracker=t;if(w!=null&&w!="")this.width=w;if(h!=null&&h!="")this.height=h;if(b!=null&&b!="")this.bgcolor=b;var lnk=(this.link==null||this.link=="")?false:true;if(lnk&&(this.tracker!=null&&this.tracker!=""))this.link=this.tracker+escape(this.link);var a='<img src="'+this.img+'" width="'+this.width+'" height="'+this.height+'" alt="" border="0" class="'+this.className+'" />';this.alt=((!lnk)?a:'<a href="'+this.link+'" target="'+this.target+'">'+a+'</a>');}
Flash.prototype.HTML=function(m,w,h,a,b){if(m!=null&&m!="")this.movie=m;if(w!=null&&w!="")this.width=w;if(h!=null&&h!="")this.height=h;if(a!=null&&a!="")this.alt=a;if(b!=null&&b!="")this.bgcolor=b;var ci=(this.ie)?' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"':'';var p=(this.ie&&this.install)?' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.ver+',0,0,0"':'';var o;var z=this.iF(this.ver);var z1=this.iF(1);if (this.movie!=null&&this.movie!=""&&(this.install||(z1&&z)||(!z1&&!z)))o='<object type="application/x-shockwave-flash" data="'+this.movie+'" width="'+this.width+'" height="'+this.height+'"'+ci+p+' id="'+this.id+'" class="'+this.className+'" >'+this.param("movie",this.movie)+((this.flashvars!=null)?this.param("flashvars",this.flashvars):"")+this.param("quality","high")+this.param("menu","false")+((this.bgcolor=="transparent")?this.param("wmode","transparent"):this.param("bgcolor",this.bgcolor))+this.alt+'</object>';else o=this.alt;return o}
Flash.prototype.writeTo=function(id,m,w,h,a,b){var el=document.getElementById(id);if(el)el.innerHTML=this.HTML(m,w,h,a,b)}


$(function(){

	//Hows Accordion at HP
	if($("#hows").length>0)
		$("#hows").accordion({
			alwaysOpen: true, 
			event: 'mouseover click', 
			selectedClass: 'open', 
			header: "dt"
		});


	//Modeal Help in Wizard
	$("a[rel=help]").click(function(){
		var href=$(this).attr("href");
		var help_id=href.substr(href.indexOf("#")+1);
		var win=$('<div><div class="modal-t"><div class="modal-i"></div></div><div class="modal-m"><div class="modal-i"><div class="modal-header"><div class="modal-question"></div><div class="clr"></div></div><div class="modal-loading">Loading</div><div class="modal-in"><div class="modal-answer"></div><div class="clr"></div></div></div></div><div class="modal-b"><div class="modal-i"></div></div></div>');
		$(".modal-question",win).append($(this).html());
		win.modal({
			overlay:80,
			overlayId: 'modal-overlay',
			containerId: 'modal-container',
			onOpen:function(dialog){
				$(".modal-in",dialog.data).hide();

				/*fix IE bug, no :hover for a without href*/
				$(".modalCloseImg",dialog.container).attr("href","#");
				dialog.data.show();
				$("#modal-overlay").fadeIn();
				$("#modal-container").slideDown();
				$.get("../ajax/help.aspx",{id: help_id},function(data){
					$(".modal-answer",dialog.data).append(data).css("max-height",$(window).height()*0.6+"px");
					$(".modal-loading",dialog.data).hide();
					$(".modal-in",dialog.data).slideDown("slow");
				});

			},
			onClose:function(){
				$("#modal-overlay").fadeOut();
				$("#modal-container").slideUp("slow",function(){
					$.modal.close();
				});
			}
		});
		return false
	});
	//modal preloader
	var modal_preloader=$("<div>").attr("id","modal-preloader").appendTo("body");
	for(var i=1;i<5;i++)$("<div>").addClass("i"+i).appendTo(modal_preloader);

	// fix PNG at "(?)" images in IE6
	$.ifixpng('../img/pixel.gif');
	$(".wit img").ifixpng();



	//WIT help

	if($(".wit").length>0){
		$(".wit").attr("title","").children("<img>").attr("alt","").attr("title","");
		$(".wit").tooltip({
			bodyHandler:function(){
				var html=$('<div id="tooltip-loading">Loading</div><div id="tooltip-in"></div>');

				var href=$(this).attr("href");
				var help_id=href.substr(href.indexOf("#")+1);
				

				$.get("../ajax/wit.aspx",{id:help_id},function(data){

					
		
							$("#tooltip-loading").hide();
							$("#tooltip-in").html(data);
							$.tooltip.update();
		
				});

				return html;
			}, 
			showURL: false
			
		}).click(function(){return false});
	}


	// btn hover fx
	$(".button button")
		.mouseover( function(){ $(this).parent().addClass('button-over') } )
		.mousedown( function(){ $(this).parent().addClass('button-down') } )
		.mouseout( function(){ $(this).parent().removeClass('button-over button-down') } )
		.mouseup( function(){ $(this).parent().removeClass('button-over button-down') } );


	$("form input[type=text]").add("form input[type=password]").addClass("textinput");

	
	if($("#txtFrom").length){
		$("#txtFrom").click(function(){$("#listDate2").get(0).checked=1}).datepicker({ maxDate: new Date() });
		$("#txtTo").click(function(){$("#listDate2").get(0).checked=1}).datepicker({ maxDate: new Date() });
		$("#cbSelect").click(function(){$("#listDate1").get(0).checked=1});
	}
		
	$(".listinglook .fade").ifixpng();
	if ($.browser.msie && ($.browser.version < 7)) {
		$('.listinglook').css({overflow:'hidden'});
		$(".listinglook .fade").css({position:'absolute',right:'-1px',width:'675px',height:'171px'})
	}

	$(".home .frame .woman").ifixpng();



//Galleybox

	function galleryImages(path){
		return [
			{
				img:path+"img/listing-google.png",
				thumb:path+"img/listing-google-tn.png",
				title:"Priority Placement Listing on Google&trade;"
			},
			{
				img:path+"img/listing-google-map.png",
				thumb:path+"img/listing-google-map-tn.png",
				title:"Priority Placement Listing on Google&trade;"
			},
			{
				img:path+"img/listing-yahoo.png",
				thumb:path+"img/listing-yahoo-tn.png",
				title:"Priority Placement Listing on Yahoo!&reg;"
			}
			];
	};


	if(typeof($.fn.gallerybox)=="function"){

		$("#ad_example_wizard").gallerybox({
			images:galleryImages("../")
		});

		$("#ad_example_hp, #ad_example_hp2").gallerybox({
			images:galleryImages("")
		});

	}



//Survey


		$("#btnStopStart").click(function(){
			
			if($(this).val()=="Stop"){
				if(!$(this).attr("override")){
					showSurvey();
					return false;
				}
			}
		
		});

		function showSurvey(){
			var survey_win_html=$('<div class="modal-win"><div class="modal-t"><div class="modal-i"></div></div><div class="modal-m"><div class="modal-i"><div class="modal-header">Please share you opinion with us!</div><div class="modal-in"><p>Please help us improve our services by participating in this simple market research.</p><p><strong>What are the/your reasons for pausing the campaign?</strong></p> <form id="survey-form"><div id="survey-list"></div> <div class="btnset"><span class="button button-small"><span><button type="button" id="modal-cancel">Cancel</button></span></span><span class="button button-green"><span><button type="submit" id="modal-submit">Submit Option &amp; Stop Campaign</button></span></span></div></form> </div></div></div><div class="modal-b"><div class="modal-i"></div></div></div>');


			var survey_win=$(survey_win_html).modal({
				overlay:80,
				overlayId: 'modal-overlay',
				containerId: 'modal-container',
				onOpen:function(dialog){

					/*fix IE bug, no :hover for a without href*/
					$(".modalCloseImg",dialog.container).attr("href","#");



					var surveyList=$('#survey-list',survey_win_html);
					surveyList.empty();

					var list=[
						{id:"surveySpentBudget",label:"Our marketing budget has been spent."},
						{id:"surveyTooComplicated",label:"The service is too complicated for me."},
						{id:"surveyNotEffective",label:"Current campaign was not effective."},
						{id:"surveyAdNotShown",label:"My ad is not being shown."},
						{id:"surveyWantTryAnother",label:"I want to try another online advertising provider."}
					];

					for(var i=0;i<list.length;i++){
						surveyList.append('<p><input type="checkbox" id="'+list[i].id+'" name="'+list[i].id+'" /><label for="'+list[i].id+'">'+list[i].label+'</label></p>');
					}

					surveyList.append('<p class="other"><input type="checkbox" id="surveyOther" name="surveyOther" /><label for="surveyOther">Other reason:</label><textarea id="surveyOtherText" name="surveyOtherText"></textarea></p>');
					
					$("#surveyOther",survey_win_html).click(function(){
						$("#surveyOtherText").valid();
					});

					$("#surveyOtherText",survey_win_html).click(function(){
						$("#surveyOther").attr("checked",1);
					}).blur(function(){
						$("#surveyOther").attr("checked", $(this).val() ).triggerHandler('click');
					});

					//$('#survey-list',kwcheck_win_html).append(makeKWList(data,1,1)).css("max-height",$(window).height()*0.4+"px");

					//buttons hover fx
					$('.button button',survey_win_html)
						.mouseover( function(){ $(this).parent().addClass('button-over') } )
						.mousedown( function(){ $(this).parent().addClass('button-down') } )
						.mouseout( function(){ $(this).parent().removeClass('button-over button-down') } );

					//button actions
					$('#modal-cancel',survey_win_html).click(function(){survey_win.close(false)});

					dialog.data.show();

		
					var surveyValidator = $('#survey-form',survey_win_html).validate({
						rules: {
							surveyOtherText: {
								required: "#surveyOther:checked"
								}
						},
						errorClass: 'error',
						errorElement: 'div',
						errorPlacement: function(error,element) {
							var par = element.parents('p');
							error.appendTo(par);
							var p = $.iUtil.getPosition($(element).get(0));
							var p2 = $.iUtil.getPosition($(par).get(0));
							var s = $.iUtil.getSize($(error).get(0));
							var s2 = $.iUtil.getSize($(element).get(0));
							error.css('left',(p.x-p2.x+s2.wb+5)+'px').css('top',Math.floor(p.y-p2.y-s.hb/2+s2.hb/2)+'px');
							},
						submitHandler: function(form) {
								addSurvey($('#survey-list'));
								survey_win.close(false);
						}
					});


		
				
					$("#modal-overlay").fadeIn();
					$("#modal-container").slideDown();

				},
				onClose:function(){
					
					$("#btnStopStart").attr("override","1").click();
					$("#modal-overlay").fadeOut();
					$("#modal-container").slideUp("slow",function(){
						$.modal.close();
					});
				}
			});
		}


		function addSurvey(data){
			var datacontainer=$('<div id="survey">');
			datacontainer.css({position:"absolute",height:"1px",width:"1px",overflow:"hidden",left:"-2000px"}).append(data);
			$("form").eq(0).append(datacontainer);
		}





});


