// JavaScript Document

// SECTION : static properties
Object.type							= typeof Object();
Boolean.type						= typeof Boolean();
Function.type						= typeof Function();
String.type							= typeof String();
Number.type							= typeof Number();
RegExp.type							= typeof RegExp(1);
Array.type							= typeof Array();
Function.empty						= new Function();
String.empty						= new String();
String.whiteSpace					= ' ';
dlabs.exceptions.nullReference		= 'Object reference not set to an instance of an object.';
dlabs.exceptions.invalidArgument	= 'Invalid argument.';

var addthis_pub						= 'dmseo'; 
var addthis_logo					= dlabs.settings.urls.media + '/_assets/images/turkce-bilgi.gif';
var addthis_logo_background			= 'ffffff';
var addthis_logo_color				= '333333';
var addthis_brand					= '<sup>Turkcebilgi.com</sup>';
var addthis_options					= 'facebook, stumbleupon, google, delicious, mixx, twitter, buzz, digg, diğer';
var addthis_localize				= { email: 'Arkadaşına Gönder', email_caption: 'Arkadaşına Gönder' };
var addthis_hover_delay				= 0;
var addthis_use_addressbook			= true;
/* jQuery ScrollTo */
(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/* jQuery LocalScroll */
(function($){var g=location.href.replace(/#.*/,''),h=$.localScroll=function(a){$('body').localScroll(a)};h.defaults={duration:1e3,axis:'y',event:'click',stop:1};h.hash=function(a){a=$.extend({},h.defaults,a);a.hash=0;if(location.hash)setTimeout(function(){i(0,location,a)},0)};$.fn.localScroll=function(b){b=$.extend({},h.defaults,b);return(b.persistent||b.lazy)?this.bind(b.event,function(e){var a=$([e.target,e.target.parentNode]).filter(c)[0];a&&i(e,a,b)}):this.find('a,area').filter(c).bind(b.event,function(e){i(e,this,b)}).end().end();function c(){var a=this;return!!a.href&&!!a.hash&&a.href.replace(a.hash,'')==g&&(!b.filter||$(a).is(b.filter))}};function i(e,a,b){var c=a.hash.slice(1),d=document.getElementById(c)||document.getElementsByName(c)[0],f;if(d){e&&e.preventDefault();f=$(b.target||$.scrollTo.window());if(b.lock&&f.is(':animated')||b.onBefore&&b.onBefore.call(a,e,d,f)===!1)return;if(b.stop)f.queue('fx',[]).stop();f.scrollTo(d,b).trigger('notify.serialScroll',[d]);if(b.hash)f.queue(function(){location=a.hash;$(this).dequeue()})}}})(jQuery);
// SECTION : String methods
String.replace = function(){
	var _string = arguments[0];
	
	if(typeof _string !== String.type)
		return _string;
	
	if(arguments.length != 0)
		for(var i = 1, n = arguments.length; i !== n; i++)
			while(_string.indexOf(arguments[i]) !== -1){ _string = _string.replace(arguments[i],String.empty) };
	
	return _string;
};
String.format = function(){
	if(arguments.length == 0)
		return null;
	
	var _string = arguments[0];
		
	for(var i = 1, n = arguments.length; i < n; i++)		
		_string = _string.replace(RegExp('\\{' + (i-1) + '\\}','gm'),arguments[i]);
	
	return _string;
};
String.toRegExp = function(pattern, flags){
	return new RegExp(pattern.replace(/[\[\]\\{}()+*?.$^|]/g, function(m){return '\\'+m;}),flags);
};
String.isNullOrEmpty = function(value){
	return typeof value === String.type && value.length ? value.trim().length == 0 : true;
};
String.prototype.trim = function(){
	return this.replace(RegExp.filter.whitespace,String.empty);
};
String.prototype.toHex = function(){
	return parseInt(this,10).toHex();
};
String.prototype.truncate = function(threshold,preserve,literal){ // refactor
	if (this.length > threshold){
		var string = this.substring(0,threshold).replace(/\w+$/,'').trim();
		
		return (preserve) ? String.format('{0} <span style="display:none;">{1}</span>',(literal) ? string + literal : string,escape(this)) : (literal) ? string + literal : string;
	}
	
	return (this) ? this.toString() : '';
};
// SECTION : RegExp methods
RegExp.filter = {
	whitespace: /^\s+|\s+$/g,
	nonAlphaNumeric: /[^0-9a-zA-Z]/g,
	nonNumeric: /[^0-9]/g,
	nonAlpha: /[^a-zA-Z]/g
};
RegExp.match = {
	alphaNumeric : /^[0-9a-zA-Z]+$/,
	alphaNumericWhitespace : /^[0-9a-zA-Z\s]+$/
};
// SECTION : Array methods
Array.prototype.contains = function(value){
	for (var i = 0, n = this.length; i < n; i++)
		if(this[i] === value)
			return true;
			
	return false;
};
Array.prototype.remove = function(from, to){
	var rest = this.slice((to || from) + 1 || this.length);
	
	this.length = from < 0 ? this.length + from : from;

	return this.push.apply(this, rest);
};
if(!Array.prototype.indexOf){ // ECMA-262 standard
	Array.prototype.indexOf = function(elt /*, from*/){
		var len = this.length;
		var from = Number(arguments[1]) || 0;
    
		from = (from < 0)
			? Math.ceil(from)
			: Math.floor(from);
    
		if(from < 0)
			from += len;

		for(; from < len; from++)
			if (from in this && this[from] === elt)
				return from;

		return -1;
	};
}

function switchTab(selector, speed){ // refactor: jQuery plugin
	var $tabs = jQuery(selector + ' .TabNavigation li');
	var $contents = jQuery(selector + ' .TabContent');

	if($contents.length < 2)
		return;

	if($contents.filter('.Selected').length == 0)
		$contents.gt(0).hide();
	
	$tabs
		.bind('click', function(){
			var $tab = jQuery(this);
			
			if($tab.hasClass('selected'))
				return false;
				
			$tabs.removeClass('selected');
			$tab.addClass('selected').blur();
			
			if(speed === 0)
				$contents.hide().eq($tabs.index(this)).show();
			else
				$contents.hide().eq($tabs.index(this)).fadeIn(speed||200).eq(0);

			//return false;
		})
		.disableTextSelect();
		
	return { tabs: $tabs, contents: $contents };
}

function initTopicGuideMenu(){ // refactor: add to namespace and avoid hardcoding selectors to allow reusablity
	$('.haveSubNav').mouseover(function(){
		$(this).children("a").css("backgroundPosition", "right -17px");
		$('.subNav').eq($('.haveSubNav').index(this)).show();
	});
	$('.haveSubNav').mouseout(function(){
		$(this).children("a").css("backgroundPosition", "right 8px");
		$('.subNav').eq($('.haveSubNav').index(this)).hide();
	});
}

function LoginBox(){
	
}
function SearchBox(options){
	var self = this;

	self.types					= ['Bilgi','Ansiklopedi','Sozluk','Cevap','Harita','Muzik','Resim','Makale','Kitap'];
	self.typeDictionary         = {Bilgi: 0, Ansiklopedi: 2, Sozluk: -1, Cevap: 3, Harita: 4, Muzik: 5, Resim: 6, Makale: 7, Kitap: 8};
	self.altTabClassName		= options.altTabClassName		|| String.empty;
	self.altBlurBackground		= options.altBlurBackground		|| '#ffffff';
	self.altBlurValue			= options.altBlurValue			|| 'Sözlüklerde ara';
	self.blurValue				= options.blurValue				|| String.empty
	self.blurColor				= options.blurColor				|| '#8A9AA6';
	self.blurBackground			= options.blurBackground		|| '#ffffff url('+dlabs.settings.urls.media+'/images/google_custom_search_watermark.gif) no-repeat scroll left center';
	self.focusColor				= options.focusColor			|| '#8A9AA6';
	self.focusBackground		= options.focusBackground		|| '#ffffff';
	self.selectedTabClassName	= options.selectedTabClassName	|| 'selected';
	self.selectedTabElement		= options.selectedTab			|| null;
	self.formElement			= options.form					|| null;
	self.typeElement			= options.typeInput				|| null;
	self.inputElement			= options.input					|| null;
	
	if(self.selectedTabElement)
		jQuery(self.selectedTabElement)
			.addClass(self.selectedTabClassName);
	if(self.inputElement)
		jQuery(self.inputElement)
			.unbind('focus.SearchBox')
			.bind('focus.SearchBox', function(){ self.focus(); })
			.unbind('blur.SearchBox')
			.bind('blur.SearchBox', function(){ self.blur(); });
	if(options.selectedTab)
		jQuery(options.selectedTab).siblings('.Tab').andSelf()
			.unbind('click.SearchBox')
			.bind('click.SearchBox', function(){ self.switchTab(this); });
	if(options.button)
		jQuery(options.button)
			.unbind('click.SearchBox')
			.bind('click.SearchBox', function(){ self.submit(); });
	self.blur();
}
SearchBox.prototype.submit = function(){
	var self = this;

	if(String.isNullOrEmpty(self.inputElement.value) || self.inputElement.value == self.blurValue || self.inputElement.value == self.altBlurValue)
		return self.blur();

	self.formElement.submit();
	
	return self;
};
SearchBox.prototype.focus = function(){
	var self = this;
	
	if(self.inputElement.value == self.blurValue || self.inputElement.value == self.altBlurValue)
		self.inputElement.value = String.empty;
	
	self.inputElement.style.background = self.focusBackground;
	self.inputElement.style.color = self.focusColor;
	
	return self;
};
SearchBox.prototype.blur = function(){
	var self = this;
	
	if(String.isNullOrEmpty(self.inputElement.value) || self.inputElement.value == self.blurValue || self.inputElement.value == self.altBlurValue){
		var hasAltTabClassName = self.selectedTabElement && self.selectedTabElement.className.indexOf(self.altTabClassName) !== -1;
		
		self.inputElement.style.background = hasAltTabClassName ? self.altBlurBackground : self.blurBackground;
		self.inputElement.value = hasAltTabClassName ? self.altBlurValue : self.blurValue;
	}
	
	self.inputElement.style.color = self.blurColor;
	
	return self;
};
SearchBox.prototype.switchTab = function(tabElement, allowAutoSubmit){
	var self = this;

	self.selectedTabElement = tabElement;
	self.typeElement.value = (function(classNames){
		for(var n = classNames.length, i = self.types.length; i > 1; i--)
			for(var a = 0; a < n; a++)
				if(classNames[a] == self.types[i])
				{
					$(self.typeElement).val(i);
					return i.toString();
				}
	})(tabElement.className.split(String.whiteSpace)) || '0';
	
	jQuery(tabElement).addClass(self.selectedTabClassName).siblings().removeClass(self.selectedTabClassName);
	
	return self.submit();
};

dlabs.utils.AddThis = (function(){
	var timeoutId = null;

	return {
		open: function(element, type, delay){
			if(typeof addthis_open !== Function.type)
				throw dlabs.exceptions.nullReference;

			clearTimeout(timeoutId);
			
			timeoutId = setTimeout(function(){
				addthis_open(element, type || '', '[URL]', '[TITLE]');
			}, delay || 250);

			return false;
		},
		close: function(){
			if(typeof addthis_close !== Function.type)
				throw dlabs.exceptions.nullReference;

			clearTimeout(timeoutId);
			addthis_close();

			return false;
		},
		prompt: function(){
			if(typeof addthis_close !== Function.type || typeof addthis_sendto != Function.type)
				throw dlabs.exceptions.nullReference;
			
			clearTimeout(timeoutId);
			addthis_close();
			addthis_sendto();

			return false;									
		},
		bind: function(selector, type, delay){
			var self = this;
			
			jQuery(selector)
				.bind(options.open, function(){ return self.open(this, type, delay); })
				.bind(options.close, function(){ return self.close(); })
				.bind(options.prompt, function(){ return self.prompt(); });

			return self;
		}
	};
})();






var services = {};

function showHide(shID) {

    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}

var lwdtext='';function lwdGetActiveText(){lwdtext=(document.all)?document.selection.createRange().text:window.getSelection();if(lwdtext.toString().length>0){lwdShowMain(lwdtext);return true;}else{return false;}}function lwdShowMain(thetext){if(top.frames.length>0){top.document.search.s.value=thetext;top.document.search.submit();}else{document.search.s.value=thetext;document.search.submit();}}function trim(str){return str.replace(/^\s*|\s*$/g,'');} 
