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)}

var rootpath='/';
var imgpath=rootpath+'img/';

var lng={
  name:'en',
  dialog:{
    button:{
      run:'Run',
      open:'Open',
      savefile:'Save File'
    },
    step1:'Click the &ldquo;%BUTTON%&rdquo; button',
    note1:'After the "File Download" window appears, <strong>click on the &ldquo;%BUTTON%&rdquo; button</strong>.',
    note2:'<strong>Important:</strong> Download may take few minutes depending on your Internet connection speed. <strong>Please be patient.</strong>',
    again:'<strong>If you have difficulty downloading, you can <a href="%LINK%">try&nbsp;to&nbsp;download again.</a></strong>',
    step2:'<strong>Follow the instructions</strong> shown during installation.'
   },
   view:{
     less:'&laquo; View Less',
     more:'View More &raquo;'
   }
}

var lng_ff={
  dialog:{
    step1:'Click the "Allow" button that appears in the top of the Firefox browser',
    step2:'Click the "Install Now" button on the Sowtware Instalation dialog',
    step3:'Then click "Restart Firefox',
    close:'Close'
  }
}

$(function(){
	$.ifixpng(imgpath+'pixel.gif');
	$('img[src$=.png],.search-img').ifixpng();
	
	$('#view-search-more').click(function(){
		var sm=$('#search-more');
		if(sm.is(':visible')){
			$(this).html(lng.view.more);
			sm.slideUp('slow',function(){$('.crn').hide().show()});
		}
		else{
			$(this).html(lng.view.less);
			sm.slideDown('slow',function(){$('.crn').hide().show()});
		}
		return false;
	})


	var dd=getDownloadDialog(imgpath+'ddialog/'+lng.name+'/');
	$('body').append('<div style="position:absolute;left:-2000px;height:1px;width:1px;overflow:hidden;visibility:hidden"><img src="'+dd.path+'" /><img src="'+imgpath+'steps.gif" /></div>');
	$('a[href$=.exe]').click(function(){
		var link=this.href;
		setTimeout(function(){
			var lightDialog = $.lightDialog({opacity:0.8,speed:600});
			lightDialog.animate($('<div class="download-steps"><div class="step step1"><strong>'+lng.dialog.step1.replace(/%BUTTON%/,lng.dialog.button[dd.button])+'</strong></div><div class="dialog"><p>'+lng.dialog.note1.replace(/%BUTTON%/,lng.dialog.button[dd.button])+'</p><p><a href="'+link+'"><img src="'+dd.path+'" style="border:0"/></a></p><p>'+lng.dialog.note2+'</p><p>'+lng.dialog.again.replace(/%LINK%/,link)+'</p></div><div class="step step2">'+lng.dialog.step2+'</div><a href="#" id="light-dialog-close"></a></div>'),{excenter:{x:-450,y:8}});
      $('#light-dialog-close').click(function(){
        lightDialog.close();
        return false;
      });
		},200);
		return true;
	});


  if(/Firefox/.test(navigator.userAgent)){
    $('body').addClass('firefox');
  }

  $('a[href$=.xpi]').click(function(){
      var params=[];
      var icopath=location.protocol+'//'+location.hostname + imgpath+'firefox/inbox_ico.png';
      params['Inbox Toolbar']={
        'URL':this.href,
        'IconURL':icopath,
        toString:function(){ return this.URL; }
      };
    
      //FF3 only
      if(/\/3./.test(navigator.userAgent)){
        setTimeout(function(){
          $(window).resize(showFirefoxHowto)
          InstallTrigger.install(params);
        },100);
        return false;
         
      }

  });

  function showFirefoxHowto(){
    window.scrollTo(0,0)
    if($('#firefox-howto').length==0){
      var div=$('<div id="firefox-howto"><div class="firefox-howto-in"><div class="firefox-howto-step1"><div class="firefox-howto-step1-in"><strong>1.</strong> '+lng_ff.dialog.step1+'<img src="'+imgpath+'firefox/step1.png" /></div></div><div class="firefox-howto-step2"><strong>2.</strong> '+lng_ff.dialog.step2+'<img src="'+imgpath+'firefox/step2.png" /></div><div class="firefox-howto-step3"><strong>3.</strong> '+lng_ff.dialog.step3+'<img src="'+imgpath+'firefox/step3.png" /></div><div class="clr"></div></div><a href="#" id="firefox-howto-close">'+lng_ff.dialog.close+' <strong>&times;</strong></a></div>').hide().appendTo('body');
      div.slideDown('fast');

      $('#firefox-howto-close').click(function(){
        $('#firefox-howto').remove();
        return false
      });
    }
    $(window).unbind('resize',showFirefoxHowto)
  }


});




//steps----------------------------------------

function getDownloadDialog(apppath){
	if(!apppath)apppath="img/"
	var agent=navigator.userAgent,o,b="open";
	var test=function(s){return (agent.search(new RegExp(s))!=-1)}
	if(test('Firefox/2')){o="ff2xp";b="savefile"}
  else if(test('Firefox/3')){o="ff3xp";b="savefile"}
	else if(test('Win 9x')||test('Windows 98')||test('Windows 95')||test('Windows NT 5.0'))o="IE6Win9x";
	else if (test('Windows NT 5.1')&&(test('MSIE 7')||test('MSIE 8'))){o="IE7xp";b="run"}
	else if (test('Windows NT 5.1')&&test('SV1')){o="IE6xpsp2";b="run"}
	else if (test('Windows NT 5.1'))o="IE6xpsp1";
	else if (test('Windows NT 6.0')||test('Windows NT 6.1')){o="IE7vista";b="run"}
	else o="IE6xpsp1";
	return {path:apppath+o+'.gif',button:b}
}


/*
 * jQuery Light Dialog Plugin
 * Author (c) Miroslav Peterka - wiki@seznam.cz
 * 2008 (c) Xacti Group
 * @version 0.0.6
 */


;(function($) {

	$.lightDialog = function(option){

		var options={
			modal:false,
			onClose:null,
			opacity:0.9,
			centerOnScroll:true,
			excenter:{x:0,y:0},
			speed:400
		};

		var lightDialog = new lightDialogClass($.extend(options,option));
		return lightDialog;
	}

		
	function lightDialogClass(options){
		this.options=options;
		this.resizeFce = null;
		this.scrollFce = null;
		return this;
	}
	
	lightDialogClass.prototype.open = function (el){
		if($.browser.msie && $.browser.version < 7)
			$('embed, object, select').css({ 'visibility' : 'hidden' });
		$('<div id="light-dialog"><div id="light-dialog-window"></div><div id="light-dialog-overlay"></div><div id="light-dialog-loader"></div></div>').appendTo('body');
		$('#light-dialog-loader').css({position:'absolute',left:'-4000px',top:0});
		$('#light-dialog-overlay').hide().css('opacity',this.options.opacity).fadeIn(this.options.speed/2);
		
		if(!this.options.modal){
			var that=this;
			$('#light-dialog-overlay').click(function(){that.close()});
		}

		if(el)$('#light-dialog-window').append(el);
		
		var that=this;

		this._scrollFce=(this.options.centerOnScroll) ?
			function(){
				placeDialogBg();
				placeDialogWin(that.options);
			}
		:
			function(){
				placeDialogBg();
			};

		this._resizeFce=function(){
				placeDialogBg();
				placeDialogWin(that.options);
		}

		this._resizeFce();


		$(window).bind('resize',this._resizeFce);
		$(window).bind('scroll',this._scrollFce);

	}

	lightDialogClass.prototype.close = function (){
		if( typeof(this.options.onClose) == 'function' )
			this.options.onClose();
		
		$(window).unbind('resize',this._resizeFce);
		$(window).unbind('scroll',this._centerFce);

		$('#light-dialog-window').hide();
		$('#light-dialog-overlay').fadeOut(this.options.speed/2,function(){$('#light-dialog').remove()});
		if($.browser.msie && $.browser.version < 7)
			$('embed, object, select').css({ 'visibility' : 'visible' });
		return false;
	}

	lightDialogClass.prototype.animate = function(el,options){
		var first=false;

		if( $('#light-dialog').length == 0) {
			this.open();
			$('#light-dialog-window').css({height:10,width:10,opacity:0});
			first=true;
		}


		this.options=$.extend(this.options,options)
		
		var loader=$('#light-dialog-loader');
		el.appendTo(loader);

		var w=loader.width();
		var h=loader.height();

		var img=el.get(0);
		var bg=$('#light-dialog-overlay').get(0);
		var middle={x:bg.offsetWidth/2+this.options.excenter.x,y:bg.offsetHeight/2+this.options.excenter.y};
		var size={x:img.offsetWidth/2,y:img.offsetHeight/2};
		var x=bg.offsetLeft+middle.x-size.x;
		var y=bg.offsetTop+middle.y-size.y;
		if(x<0)x=0;
		if(y<0)y=0;

		el.hide();
		
		$('#light-dialog-window').animate({top: y+"px" ,left: x+"px",width:w+"px",height:h+"px",opacity:1},this.options.speed,function(){
			el.show();
      if(this.style.removeAttribute)this.style.removeAttribute('filter');
		}).html('').append(el);

	}




/*helper functions */

	function placeDialogBg(){
		var bg=$('#light-dialog-overlay').get(0);
		var scrolled=(window.pageXOffset==undefined)?{x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop}:{x:window.pageXOffset,y:window.pageYOffset};
		bg.style.width=0;
		bg.style.height=0;
		var winsize=(window.innerHeight==undefined)?{x:document.documentElement.clientWidth+'px',y:document.documentElement.clientHeight+'px'}:{x:'100%',y:'100%'};
		bg.style.top=scrolled.y+'px';
		bg.style.left=scrolled.x+'px';
		bg.style.width=winsize.x;
		bg.style.height=winsize.y;
	}

	function placeDialogWin(options){
		var img=$('#light-dialog-window').get(0);
		var bg=$('#light-dialog-overlay').get(0);
		var middle={x:bg.offsetWidth/2+options.excenter.x,y:bg.offsetHeight/2+options.excenter.y};
		var size={x:img.offsetWidth/2,y:img.offsetHeight/2};
		var x=bg.offsetLeft+middle.x-size.x;
		var y=bg.offsetTop+middle.y-size.y;
		if(x<0)x=0;
		if(y<0)y=0;
		img.style.top=y+"px";
		img.style.left=x+"px"
	}


})(jQuery);



function parseQuerystring(){
	var qs = location.search.substring(1, location.search.length);
	if (qs.length == 0){ 
			return {};
	}else{
		qs = qs.replace(/\+/g, ' ');
		var ret={};
		var args = qs.split('&');
		for (var i=0; i< args.length; i ++ ){
			var value;
			var pair = args[i].split('=');
			var name = unescape(pair[0]);
			if (pair.length == 2){	
				value = unescape(pair[1])
			}else{
				value = name
			}
			ret[name]=value;
		}
		return ret;
	}
}

var lastKeyword=false;

function saveNewKeyword(el){
  if(lastKeyword===false){
    lastKeyword=el.defaultValue;
  }
  var keyword=el.value;

  setTimeout(function(){
    if(keyword!="" && keyword != lastKeyword){
      lastKeyword=keyword;
      
      var params=parseQuerystring();
      params['k']=keyword;
      params['t']='';
      $.ajax({
        url:rootpath+'lp/savecook.aspx',
        type:'get',
        data:params,
        dataType:'json',
        cache:false
      });
    }
  },100);
}