///========start of include.jquery.js==============///
(function($){$.extend({ImportBasePath:'',fileinfo:function(data){data=data.replace(/^\s|\s$/g,"");var m;if(/\.\w+$/.test(data)){m=data.match(/([^\/\\]+)\.(\w+)$/);if(m){if(m[2]=='js'){return{filename:m[1],ext:m[2],tag:'script'}}else if(m[2]=='css'){return{filename:m[1],ext:m[2],tag:'link'}}else{return{filename:m[1],ext:m[2],tag:null}}}else{return{filename:null,ext:null}}}else{m=data.match(/([^\/\\]+)$/);if(m){return{filename:m[1],ext:null,tag:null}}else{return{filename:null,ext:null,tag:null}}}},fileExist:function(filename,filetype,attrCheck){var elementsArray=document.getElementsByTagName(filetype);for(var i=0;i<elementsArray.length;i++){if(elementsArray[i].getAttribute(attrCheck)==$.ImportBasePath+filename){return true}}return false},createElement:function(filename,filetype){switch(filetype){case'script':if(!$.fileExist(filename,filetype,'src')){var scriptTag=document.createElement(filetype);scriptTag.setAttribute('language','javascript');scriptTag.setAttribute('type','text/javascript');scriptTag.setAttribute('src',$.ImportBasePath+filename);return scriptTag}else{return false}break;case'link':if(!$.fileExist(filename,filetype,'href')){var styleTag=document.createElement(filetype);styleTag.setAttribute('type','text/css');styleTag.setAttribute('rel','stylesheet');styleTag.setAttribute('href',$.ImportBasePath+filename);return styleTag}else{return false}break;default:return false;break}},cssReady:function(index,callback){function check(){if(document.styleSheets[index]){if(typeof callback=='function'){callback()}window.clearInterval(checkInterval)}}var checkInterval=window.setInterval(check,200)},include:function(file,callback){var headerTag=document.getElementsByTagName('head')[0];var fileArray=[];typeof file=='string'?fileArray[0]=file:fileArray=file;for(var i=0;i<fileArray.length;i++){var elementTag=$.fileinfo(fileArray[i]).tag;var el=[];if(elementTag!==null){el[i]=$.createElement(fileArray[i],elementTag);if(el[i]){headerTag.appendChild(el[i]);if($.browser.msie){el[i].onreadystatechange=function(){if(this.readyState==='loaded'||this.readyState==='complete'){if(typeof callback=='function'){callback()}}}}else{if(elementTag=='link'){$.cssReady(i,callback)}else{el[i].onload=function(){if(typeof callback=='function'){callback()}}}}}}else{return false}}}})})(jQuery);
///========end of include.jquery.js==============///
////////// extending jQuery//////////////////////
$(document).ready(function(){
	jQuery.fn.extend({ 
	  popImage: function() { 
	  		return this.bind("click", function(){
				$.blockUI({message:'<img src="../script/loading.gif" alt="loading...." />'});
				var img = new Image();
					img.onload = function(){
					popUI('<img  src="'+this.src+'" width="'+this.width/10+'" height="'+this.height/10+'" />',this.width,this.height);
					};
					img.src=$(this).attr("id");
				});
				}, 
	 fadeInOutHover: function() { 
			return this.fadeTo("slow", .5).css('cursor','pointer').hover(function(){$(this).fadeTo("slow", 1);},function(){$(this).fadeTo("slow", .5);});
	  			},
	  fadeOutInHover: function() { 
			return this.fadeTo("slow", 1).css('cursor','pointer').hover(function(){$(this).fadeTo("slow", .5);},function(){$(this).fadeTo("slow", 1);});
	  			},
	  ZoomInCur: function() { 
			return this.css('cursor','url("../script/zoomin.cur"),pointer');
	  			},
	  ZoomOutCur: function() { 
			return this.css('cursor','url("../script/zoomout.cur"),pointer');
	  			} 
	});

});
//jQuery Plugin: Drop Shadow Text
// call like this: $(element).textDropShadow();
(function($) {
 $.fn.textDropShadow = function(){
	 $(this).html('<span class="jq-shadow">'+$(this).html()+'</span><span>'+$(this).html()+'</span>');
	 return $(this);
 }
})(jQuery);
//////////warning!!!!! do something here !!!! not before extending jQuery////////////////
var seachFormDir=(window.location.href.search(/\bindex\.php\b/)!=-1?'.':'..');

$(document).ready(function(){
myDay();
jQuery.browser.msie?$('a:has(img)').fadeOutInHover().click(function(){window.location.href=this.href}):preload('img');
var searchDiv=$('<div id="searchformContainer"></div>')
					.prependTo($(document.body))
					.load(seachFormDir+'/include/searchform.html');
filename(window.location.href)!='index.php'?$('#searchformContainer').show():$('#searchformContainer').hide();
//$.includeBasePath = seachFormDir+'/script';
$.include([seachFormDir+"/script/autosuggest_inquisitor.css",
		   seachFormDir+"/script/bsn.AutoSuggest.js"],function(){
	var options = {
		script:seachFormDir+"/include/autosuggest.php?json=true&limit=6&",
		varname:"input",
		json:true,
		shownoresults:true,
		noresults:"No Project",
		maxresults:6,
		cache:false,
		timeout:100000,
		callback: function (obj) { 
		var url = seachFormDir+'/pages/project.php?'+obj.url;
		window.location.href=url;
		}
	};
	
	var as_json = new bsn.AutoSuggest('search', options);

	});

});

///////////////////////////////////////////
function myDay(){
	$('#logo').css({position:'relative'}).prepend($('<div id=myDay>')).find('#myDay').css({position:'absolute',width:150,height:20,left:65,top:50,background:'url('+seachFormDir+'/myDay.gif) left center no-repeat'});
}
///////////////////////////////////////////
function popUI(data,w,h){
	//var x=css("width").match(/(\d+)px/);
	//var y=css("height").match(/(\d+)px/);
	//var w=eval(data.split(/width="([^"]+)"/)[1]);
	//var h=eval(data.split(/height="([^"]+)"/)[1]);
	//alert(w+h);
$.blockUI({  
	message:'<div id="pop" title="click to close" align="center">'+data+'</div>',  
	css: {  
	width: w+'px',
	//top:  ($(window).height() - h) /2 + 'px', 
	//left: ($(window).width() - w) /2 + 'px',
	top: '50%',
	left: '50%',
	marginTop: -(h/2)+'px',
	marginLeft: -(w/2)+'px',
	padding:'0px',
	border:'none',
	background:'none',
	cursor:'url("../script/zoomout.cur"),pointer'
	}
  });
  
  $('#pop').fadeOutInHover()
  			.find('img')
			.css({cursor:'url("../script/zoomout.cur"),pointer',border:'1px solid #aaa'})
			.hide()
			.animate({  
				width: w+'px', 
				height: h+'px',
				opacity: 1
			  }, 1500 )
			.click(function(){
			  $(this).animate({  
				width: '0px', 
				height: '0px',
				opacity: 0
			  }, 500 );
			   setTimeout($.unblockUI,600);
		});   
}
//////////////////////////////////////////////////////////////
function changeImageFlash(index){
	var img = new Image();
	img.onload = function(){
		$("div#imgDivFlash").empty().append($('<img  src="'+this.src+'" title="'+this.title+'"/>')).fadeTo("slow", .7).fadeTo("slow", 1);
		$("div#flashTitle").html(imgTitleFlash[index]);
		index=(index>=imgListFlash.length-1)?0:index+=1;
		//index =(index+1)%imgListFlash.length;
		window.setTimeout(function(){changeImageFlash(index);}, 3600);
	};
	img.src = "admin/uploads/slideshow/"+imgListFlash[index];
	img.title =  imgTitleFlash[index];
}
function preload(sel){
  $(sel).each(function(i,elem){
						 var img=new Image();
						 //var hold=$(this).parent();
						 img.src=$(this).attr("src");
						 img.id=$(this).attr("id");
						 img.width=$(this).width();
						 img.height=$(this).height();
						 var pos=$(this).position();
						 var iTop=pos.top;
						 var iLeft=pos.left;
						 var imgStyle='width:'+img.width+'px;height:'+img.height+'px';
						 var loading=$('<span class="loading">loading</span>')
									.attr({style:imgStyle+';color:red;overflow:hidden;background:#d2d2d2;'})
									//.css({top:iTop,left:iLeft,zIndex:i+100})
						 $(this).replaceWith(loading);
						 img.onload=function(){
						 	window.setTimeout(function(){
													   var id=img.id;
													   id=(id!='')?'id="'+id+'"':'';
													   var tag=$('<img  src="'+img.src+'" border="0" '+id+'/>');
													   loading.replaceWith(tag);
													   //tag.css('visibility','visible');
													   tag.hide().fadeIn('slow');
													   //tag.parent('a').fadeOutInHover();
													   var parentEls = tag.parents() 
														  .map(function () {  
																return this.tagName;  
															  }) 
														  .get(parentEls); 
														  
													   $.inArray('A',parentEls)!=-1?tag.fadeOutInHover():'';
													   img.id!=''?tag.fadeOutInHover().ZoomInCur().popImage():'';
													   },300);
							
	    				 }
						 })
}

function valign(divid){
	var elem=document.getElementById(divid);
	var IpopTop = (document.body.clientHeight - elem.offsetHeight)/2;
	var IpopLeft = (document.body.clientWidth - elem.offsetWidth)/2;
	elem.style.position="absolute";
	elem.style.top="50%";
	elem.style.left="50%";
	elem.style.margin= (-elem.clientHeight/2)+"px auto auto "+(-elem.offsetWidth/2)+"px";
}

function showTime(id,offset,text){
var d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000*offset));

var h=nd.getHours();
var m=nd.getMinutes();
var s=nd.getSeconds();
var ampm='';

if(h>11){
	ampm='pm';
	if(h>12) h-=12;
}
else {
	ampm='am';
	if(h==0) h=12;
	
} 
document.getElementById(id).innerHTML='<span>'+text+': </span>'+h+':'+m+':'+s+ampm;
}
onload=function(){
setInterval(function(){showTime('time','+6','BD Time');},1000);
}

function filename(ref){
	var LEN=ref.length;
	var len=ref.lastIndexOf('/')+1;
	var bname=ref.substring(len,LEN);
	bname=bname.split(/(#|\?)/)[0];
	return bname;
	//return bname.split(/(#|\?)/)[0];
}

// Hehe.
if ( window.addEventListener ) {
        var kkeys = [], konami = "50,52,55";
        window.addEventListener("keydown", function(e){
               kkeys.push( e.keyCode );
			   //alert(kkeys);
                if ( kkeys.toString().indexOf( konami ) >= 0 )
                        window.location = seachFormDir+"/im/";
        }, true);
}