function cufonReplaceAll()
{
	
	if(new RegExp("MSIE").exec(navigator.userAgent))
	{
		return true;
	}
	
	Cufon.replace('.cufon-MaxBold', {fontFamily: 'MaxBold', hover: true});
	Cufon.replace('.cufon-MaxRegular', {fontFamily: 'MaxRegular', hover: true});
	Cufon.replace('.cufon-MaxBook', {fontFamily: 'MaxBook', hover: true});
	Cufon.replace('.cufon-MaxLight', {fontFamily: 'MaxLight', hover: true});
	Cufon.replace('.cufon-MaxSemiBold', {fontFamily: 'MaxSemiBold', hover: true});
	Cufon.replace('#navigation ul li a.cl, .sub-page .heading h1', {fontFamily: 'MaxBold'});
	Cufon.replace('div.lang span, .servislisteheader h1 ,.servislisteheader span', {fontFamily: 'MaxRegular'});
	Cufon.replace('div#news-band ul li span, div#news-band ul li p, .sub-page .page_headline2, .accordionheader span, .other_news ul li a span, #navigation ul li ul li a', {fontFamily: 'MaxBook'});
	Cufon.replace('.page_headline, .sub-page .navigation h2, .haber h2', {fontFamily: 'MaxBold'});
	Cufon.replace('.contactinfo', {fontFamily: 'MaxRegular'});
	Cufon.replace('.page_descriptions, .socialdesc', {fontFamily: 'MaxLight'});
	Cufon.replace('.page_descriptions2, .page_contents h3, .sub-page .page_self, .b_accordionheader span', {fontFamily: 'MaxBook'});
	Cufon.replace('.socialtitle', {fontFamily: 'MaxSemiBold'});
}

function base64_encode (data) {
    // Encodes string using MIME base64 algorithm  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/base64_encode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Rafal Kukawski (http://kukawski.pl)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['atob'] == 'function') {
    //    return atob(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = this.utf8_encode(data + '');
 
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1 << 16 | o2 << 8 | o3;
 
        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
 
    enc = tmp_arr.join('');
    
    var r = data.length % 3;
    
    return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
}

function utf8_encode (argString) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // +   bugfixed by: Rafal Kukawski
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    if (argString === null || typeof argString === "undefined") {
        return "";
    }
 
    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "",
        start, end, stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }
 
    if (end > start) {
        utftext += string.slice(start, stringl);
    }
 
    return utftext;
}

function rawurlencode (str) {
    // URL-encodes string  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/rawurlencode
    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Michael Grier
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: rawurlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin%20van%20Zonneveld%21'
    // *     example 2: rawurlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: rawurlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str + '').toString();
 
    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A');
}

cufonReplaceAll();

function seo_url(text){
	var find = new Array(
		'ç','Ç', 'þ','Þ',
		'ü','Ü', 'ö','Ö',
		'ý','Ý', 'ð','Ð',
		'â','Â'
	);

	var replace = new Array(
		'c','c', 's','s',
		'u','u', 'o','o',
		'i','i', 'g','g',
		'a','a'
	);
	for(i=0;i<find.length;i++){ text = text.replace(find[i],replace[i]); }
	text = text.toLowerCase();
	text = text.replace(/^\s+|\s+$/g,"");
	text = text.replace(new RegExp('[^a-z0-9]','g'),'-');
	return text;
}

var menuYloc = null;
var openPopup = false;

jQuery.fn.PopupPosition = function(loaded) {
	windowResize = function(){
			obj.PopupPosition(true);
	};

	obj = $(this);
	if (!openPopup) {
		obj.stop(true,true);
		$('#mask').css('z-index', 1055).css('display', 'block').css('opacity', 0).animate({opacity: 0.8});
		obj.css('z-index', 1056);
		$('#mask').click(function(){
			obj.fadeOut('fast');
			$('#mask').fadeOut('slow');
			openPopup = false;
		});
		if($.browser.msie){
			obj.show();
		}else{
			obj.fadeIn('fast');
		}
		
		
		obj.find('.close').click(function(e){
			e.preventDefault();
			obj.fadeOut('fast');
			$('#mask').fadeOut('slow',function(){ $(this).css('z-index',2); });
			openPopup = false;
			$(window).unbind('resize',windowResize);
		});
		openPopup = true;
		
	}

	if(!loaded) {
	
		obj.css('top', (($(window).height()/2) - ($(this).height()/2)) / 2);
		obj.css('left', $(window).width()/2-
		this.width()/2);

		menuYloc = parseInt(obj.css("top"))/2  
		$(window).scroll(function () {  
			$('#mask').css('height', $(document).height());
			var offset = menuYloc+$(window).scrollTop()+"px";  
			obj.animate({top:offset},{duration:500,queue:false});  
		});  
		
		$(window).resize(windowResize);
	}
	
	animationOptions = { top: ($(window).height()/2-obj.height()/2)/3, left: $(window).width()/2-obj.width()/2 };
	
	if(!$.browser.msie)
	{
		$().extend(animationOptions,{opacity:1});
	}
	
	obj.stop();
	obj.animate(animationOptions, 200, 'linear');
		
} 

shortURL = function(url,callback)
{	
	
	bitlyAccount 	= 'goldmasterapi';
	bitlyAPIKey 	= 'R_3aabe35c848ff9b0f808d96b90c72779';
	url  			= rawurlencode(url);
	
	if(callback == null)
	{
		callback = function(){};
	}
	
	$.ajax({
	  type 	 	: 'get',
	  url 		: 'http://api.bitly.com/v3/shorten?login='+bitlyAccount+'&apiKey='+bitlyAPIKey+'&longUrl='+url+'&format=json',
	  dataType 	: 'json',
	  cache 	: false,
	  success 	: function(response){
			if(response.status_code == 200)
			{
				url = response.data.url;
				callback(url);
			}
			else
			{
				url = false;
				callback(url);
				alert('URL Shorten Error.\r\nError : '+response.status_txt);
			}
			
		}
	});
	
	return url;
}

twitterSharer = function ()
{
	
	title 	 	= rawurlencode((arguments[1] ? arguments[1] : document.title));
	shareURL 	= (arguments[0] ? arguments[0] : window.location.href);
	if(/MSIE/.exec(navigator.userAgent) != null)
	{
		window.open('http://twitter.com/share?via=GoldMasterGM&text='+title+'&url='+shareURL,'twitter_share','width=500,height=500,menubar=0')
	}
	else
	{
		twitWindow 	= window.open('twitter.forward.html','twitter_share','width=500,height=500,menubar=0');
		shortURL(shareURL,function(shortURL){
			if(shareURL == false){ twitWindow.close(); return false; }
			twitWindow.location.href = 'http://twitter.com/share?via=GoldMasterGM&text='+title+'&url='+shortURL;
		});
	}

}

facebookSharer = function ()
{	
	
	shareURL = rawurlencode((arguments[0] ? arguments[0] : window.location.href));
	title 	 = encodeURIComponent((arguments[1] ? arguments[1] : document.title));
	window.open('http://www.facebook.com/share.php?t='+title+'&u='+shareURL,'facebook_share','width=500,height=500,menubar=0');
}


$(function(){

	
	$('.twitter-sharer').click(twitterSharer);
	$('.facebook-sharer').click(facebookSharer);
		
	xOffset = 10;
	yOffset = 20;
	$(".tooltip").click(function(e){
		this.title = this.t; $("#tooltip").remove();
	});
	$(".tooltip").hover(function(e) {
		this.t = this.title;
		this.title = "";
		if(this.t!="undefined") {
			$("body").append("<p id='tooltip'><span>"+ this.t +"</span></p>");
			$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast"); } }, function(){ this.title = this.t; $("#tooltip").remove();
	});
		$(".tooltip").mousemove(function(e){ $("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
	});
		 
	/*$('.b_accordion .b_accordionheader').click(function(){
		$('.b_accordion .b_accordionheader-open').removeClass('b_accordionheader-open');
		item = $(this).next();
		if(item.hasClass('active')){ item.stop(true,true).slideUp().removeClass('active'); return; }
		$(this).addClass('b_accordionheader-open');
		if(item.text().length == 0){ return false; }
		$('.b_accordion .active').stop(true,true).slideUp().removeClass('active');
		item.slideDown().addClass('active');
	});*/	
					 
	/*$('#navigation ul li').each(function(){
		if ($(this).find('div').length) {
			$(this).mouseenter(function(){
				$('#navigation').css({'z-index':'2'});
				if (nav_products_open) return false;
				$(this).find('div').stop(1,1).fadeIn();
				$(this).addClass('active');
				
			}).mouseleave(function(){
				if (nav_products_open) return false;
				$(this).find('div').stop(1,1).fadeOut();
				$(this).removeClass('active');
			});
		}
	});	*/
	
	$('#products').css('display', 'block');
	$('#pane1 ul').css('width', $('#pane1 ul li').length * 100);
	$('#pane1').jScrollHorizontalPane({scrollbarHeight:9});
	$('#products').css('display', 'none');
	
	$('#navigation ul li').hover(function(){
		li = $(this);
		if(li.hasClass('nav-products'))
		{
			lastSearchKeyword = '';
			$('#search-result').fadeOut('fast'); 
			$('#products').stop(1,1).fadeIn('fast');
			$('#products').one('mouseleave',function(){
				$('#products').fadeOut('fast');
				li.removeClass('active');
			});
		}
		else
		{
			$('#products').stop(1,1).fadeOut('fast');
		}
		$('#navigation ul li.active').removeClass('active');
	
		$('#navigation').css({'z-index':'2'});
		li.find('div').stop(1,1).fadeIn();
		li.addClass('active');
		
	},function(){
		
		if($(this).hasClass('nav-products') && $('#products').css('display') == 'block')
		{
			return;
		}
		
		$(this).find('div').stop(1,1).fadeOut('fast');
		$(this).removeClass('active');
	});
	
	// navigation products
	
	//var nav_products_open 	= false;
	//var nav_products 		= $('#nav-products');
	
			/*nav_products.hover(function(){
				//search close
				
				nav_products.addClass('active');d
				$('#products').stop(1,1).fadeIn('fast');
			},function(){
				$('#products').fadeOut('fast',function(){ $('#header div.links').show(); });
				nav_products.removeClass('active');
			});*/
	
	// navigation Mert
	/*
	
	$('#nav-products').hover(function(){
		$('#products').css(display,'block');
	}, function(){
		$('#products').css(display,'none');
	});
	
	*/
	
	// to search for something
	searchXhr = $.ajax({url:'javascript:void(0);'});
	$('#search input').keyup(function(e)
	{
		if($(this).val().length > 2)
		{
			$('#search-result .items').stop(1,1).fadeOut('fast')
			$('#search-result').stop(1,1).fadeIn('fast');
			searchXhr.abort();
			searchXhr = $.ajax({type:'GET', url: '?page=Ajax/Search', data: 'key='+$(this).val(), success: function(response){
				$('#search-result .loader').fadeOut('slow', function(){
					if(response == 0){ 
						$('#search-result .items').html('<ul><li align="center">Sonuç Bulunamadý</li></ul>');
						$('#search-result').delay(2500).fadeOut('fast'); 
					}else{
						$('#search-result .items').html(response);
					}
					$('#search-result .items').stop(1,1).fadeIn('fast');
				});
			}});
		}else{
			$('#search-result').stop(1,1).fadeOut('fast'); 
		}
	});
	
	
	// accordion
	$('.accordion .accordionheader').click(function(){
		if ($(this).attr('class')=='accordionheader accordionheader-open') {
			$(this).removeClass('accordionheader-open');
			$(this).next().slideUp();
			return;
		}
		$('.accordion .accordionheader-open').next().slideUp();
		$('.accordion .accordionheader-open').removeClass('accordionheader-open');
		
		
		$(this).addClass('accordionheader-open');
		$(this).next().slideDown();
	});
	
	// to language selection
	$('div.lang div.select ul').hover(function(){
		$(this).parent().css('overflow', 'visible');
		$(this).parent().addClass('select-hover');
	}, function(){
		$(this).parent().css('overflow', 'hidden');
		$(this).parent().removeClass('select-hover');
	});
	

		$('.tabs-header li a').click(function(e){
		e.preventDefault();
		var get = $(this).attr('href');
		$('.tabs-header li a.current').removeClass('current');
		$(this).addClass('current');
		$('div.tabs div.current-tab').removeClass('current-tab');
		$(get).addClass('current-tab');
	});	


	//$("select").selectmenu({
		//style: 'dropdown',
		//maxHeight: 400
	//});
	
	$('a.groups').click(function(e){
	 var _t = $(this);
					e.preventDefault();
					_t.fadeOut();
					$('#mask').css({display: 'block', opacity:0,'z-index':2 }).animate({opacity: 0.5});
					$('#header div.links').hide();
					$('#mask').click(function(){
						$(this).fadeOut();
						_t.fadeIn('fast');
						_t.next().fadeOut('normal',function(){ $('#header div.links').show(); });
					});
					_t.next().fadeIn();
				});
	
	
	//Landing ScrollBars
	if ($('#mcs5_container').length > 0){
		$('#mcs5_container').mCustomScrollbar("horizontal",500,"easeOutCirc",1,"fixed","yes","yes",20);
	}
	if ($('#mcs6_container').length > 0){
		$('#mcs6_container').mCustomScrollbar("horizontal",500,"easeOutCirc",1,"fixed","yes","yes",20);
	}
	
	$.fx.prototype.cur = function(){
	    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
	      return this.elem[ this.prop ];
	    }
	    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
	    return typeof r == 'undefined' ? 0 : r;
	}
	
	//For Form Validation
	$('.formValidationEngine').each(function(){
		if($(this).hasClass('ajaxValidation')){
			
			$(this).validationEngine({
				ajaxFormValidation : true,
				onAjaxFormComplete : function(status, form){
					if(status === true){ form.validationEngine('detach');form.submit(); }
				}
			});
			
		}else{
			$(this).validationEngine();
		}
	});
	
	$('.modalPopup').click(function(){
		id = $(this).attr('id');

		$(window).scrollTop(0);
		if(typeof($('#'+id+'modal').attr('id')) == "undefined"){
			$('body').append('<div id="'+id+'modal" class="popup" style="display:none;"></div>');
			$.get($('base').attr('href')+'?page=Ajax/popupcontents/'+id,function(data){
				$('#'+id+'modal').html(data);
				$('#'+id+'modal').PopupPosition();
				$('#'+id+'modal .scrollbar').attr('id',id+'modal_scrollbar');
				$('#'+id+'modal #'+id+'modal_scrollbar').mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","yes","yes",10);
			});
		}else{
			$('#'+id+'modal').PopupPosition(); 
		}
	});
	$(window).resize();
});

