function StringBuffer() {
   this.buffer = [];
   this.bufferLength = 0;
}

StringBuffer.prototype.append = function(string) {
   this.buffer.push(string);

   if (string != null) {
      this.bufferLength += string.length;
   }

   return this;
}

StringBuffer.prototype.toString = function() {
   return this.buffer.join("");
}

StringBuffer.prototype.length = function() {
   return this.bufferLength;
}

function showModalWindow(response) {
	jQuery(document).ready(function () {
 		$.zadebox(response);     
    });
}

function closeModalWindow() {
    jQuery(document).ready(function () {
        $.zadebox.close();
    });
}

function showCampaign(){
	jQuery(document).ready(function () {
        $.get(baseurl+'pop/campaign/', function(data) {
		 	showModalWindow(data);
		});
    });
}

function showVipRequiredBox()
{
	
	jQuery(document).ready(function () {
        $.get(baseurl+'pop/vip-required/', function(data) {
		 	showModalWindow(data);
		});
    });
	return false;
	
}



/* plugin */
jQuery.create = function () {
    if (arguments.length == 0) return [];
    var args = arguments[0] || {},
        elem = null,
        elements = null;
    var siblings = null;

    // In case someone passes in a null object,
    // assume that they want an empty string.
    if (args == null) args = "";
    if (args.constructor == String) {
            if (arguments.length > 1) {
                var attributes = arguments[1];
                if (attributes.constructor == String) {
                    elem = document.createTextNode(args);
                    elements = [];
                    elements.push(elem);
                    siblings = jQuery.create.apply(null, Array.prototype.slice.call(arguments, 1));
                    elements = elements.concat(siblings);
                    return elements;

                } else {
                    elem = document.createElement(args);

                    // Set element attributes.
                    var attributes = arguments[1];
                    for (var attr in attributes)
                    jQuery(elem).attr(attr, attributes[attr]);

                    // Add children of this element.
                    var children = arguments[2];
                    children = jQuery.create.apply(null, children);
                    jQuery(elem).append(children);

                    // If there are more siblings, render those too.
                    if (arguments.length > 3) {
                        siblings = jQuery.create.apply(null, Array.prototype.slice.call(arguments, 3));
                        return [elem].concat(siblings);
                    }
                    return elem;
                }
            } else return document.createTextNode(args);
        } else {
            elements = [];
            elements.push(args);
            siblings = jQuery.create.apply(null, (Array.prototype.slice.call(arguments, 1)));
            elements = elements.concat(siblings);
            return elements;
        }
};


function setBgColor(e, color) {
    if (e != null) {
        e.style.backgroundColor = color;
    }
}


function showModal(text, type, wait) {

    var response = '\
			<div id="dialog-box"> \
			  <TABLE width="406" border="0" cellPadding="0" cellSpacing="0"> \
				<TR> \
				  <TH>' + text.msg + '</TH> \
				</TR> \
				<TR> \
				  <TD>' + text.desc + '</TD> \
				</TR> \
			  </TABLE> \
			  <div class="footer"> <a href="javascript:void(0)" onclick="closeModalWindow()" class="box_button"> Kapat</a> </div> \
			</div>  \
			';

    showModalWindow(response);

    if (wait > 0) {
     	setTimeout(function(){$(document).trigger('close.facebox') }, close); 
    }
}

function showlostpassform(){
	jQuery(document).ready(function () {
		 jQuery.get(baseurl+"pop/lost-password/", null, function(response) {
         	showModalWindow(response);
      	 }, "html");							 
	});
}

function pencere_ac(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var ShareUrl = {
		
        facebook: function(longUrl) {
			if(longUrl){
				shareUri = longUrl;
			} else {
				shareUri = document.location.href;
			}
            window.open('http://www.facebook.com/sharer.php?title='+ encodeURIComponent(document.title) +' &u=' + encodeURIComponent(shareUri), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        google: function(longUrl) {
			if(longUrl){
				shareUri = longUrl;
			} else {
				shareUri = document.location.href;
			}
            window.open('http://www.google.com/bookmarks/mark?op=edit&title=' + encodeURIComponent(document.title) + '&bkmk=' + encodeURIComponent(shareUri), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        yahoo: function() {
            window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        myspace: function() {
            window.open('http://www.myspace.com/Modules/PostTo/Pages/?l=2&t=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        friendFeed: function(longUrl) {
			if(longUrl){
				shareUri = longUrl;
			} else {
				shareUri = document.location.href;
			}
            window.open('http://friendfeed.com/share/bookmarklet/frame#title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(shareUri), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');

        },
        mixx: function() {
            window.open('http://www.mixx.com/submit/story?title=' + encodeURIComponent(document.title) + '&page_url=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        digg: function() {
            window.open('http://digg.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        stumpleUpon: function() {
            window.open('http://www.stumbleupon.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        delicious: function() {
            window.open('http://del.icio.us/post?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        reddit: function() {
            window.open('http://reddit.com/submit?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(document.location.href), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        twitter: function(longUrl) {
			if(longUrl){
				shareUri = longUrl;
			} else {
				shareUri = document.location.href;
			}
            window.open('http://twshot.com/share.aspx?title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(shareUri), '', 'height=650,width=910,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
        },
        buzz: function(){
        window.open('http://www.google.com/buzz/post?url=' + encodeURIComponent(document.location.href));
        }
    }



$(document).ready(function () {
	
	_construct_tips = function () {
    	$('.tipped').mouseover(function () {
			var pos = $(this).offset();
			var height = $(this).height();
			var width = $(this).width();
			if (!$('#profile_tooltip').html()) {
				$('body').prepend('<div id="profile_tooltip"></div>');
			}
			$('#profile_tooltip').html('<div class="rw"><div class="lw">' + $(this).attr('alt') + '</div></div>');
			var tipwidth = $('#profile_tooltip').width();
			$('#profile_tooltip').css('display', 'block').css('z-index', '9999').css('top', (pos.top + height + 5) + 'px').css('left', ((pos.left + (Math.round(width / 2))) - (Math.round(tipwidth / 2))) + 'px');
    	}).mouseout(function () {
        $('#profile_tooltip').css('display', 'none');
    	});
	}
	$("#kontrol").click(function(){
		//$("#oyun-bar").slideToggle("slow");
		$(this).toggleClass("box-up"); 
		if (window.location.href==baseurl)
		{
			window.location.href=baseurl+"games";
		}
		else
		{
			window.location.href=baseurl;
		}
		
		return false;
	});
	
	if($('body').height() < $(window).height())
	{
		$("#footer").css({position: "absolute",left:"0px",top:($(window).height()-$("#footer").height())+"px",width:'100%'})
	}
	
	$("#duyurular-text-holder").newsTicker({
		effect: "slide"
	});
	
	($(".notification").length) ? ($(".notification").animate({opacity: 0.4},400).animate({opacity: 1},1000).animate({opacity: 0.4},400).animate({opacity: 1},1000)) : false;
	
	_construct_tips();
	
});




