// JavaScript Document


function sComments( p,thisUrl, item_id ) {
	/* 
	 $$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });
    
    $( 'tComments' ).show();
	 */
	var d = $( 'stabc-comments' );
	var url = '/comments/get';
	
	var params = 'url=' + thisUrl + '&p=' + p + '&item_id=' + item_id;
	new Ajax.Updater( d,
		url,
		{method: 'get', parameters: params}
	);
}

function sFavorite( thisUrl, item_id ) {
    /*
      
    $$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });
    $( 'tFavorites' ).show();

	var d = $( 'stabc-favorites' );
	*/
	thisUrl = thisUrl.replace(/'/g,"");
	thisUrl = thisUrl.replace(/http:\/\/gnctrkcll.turkcell.com.tr\//g,"");	
	item_id = item_id.replace(/'/g,"");

	var url = '/favorites/add-to-favorites';
	
	var params = 'url=' + thisUrl + '&item_id=' + item_id;
	new Ajax.Request( url,
		{
			method: 'get', parameters: params,
			onSuccess : function ( transport ) {
				alert( transport.responseText );
				}	
		}
	);
}
function sLike( thisUrl, item_id ) {
    $$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });
    $( 'tPagerate' ).show();

	var d = $( 'stabc-pagerate' );
	var url = '/pagerate/like';
	
	var params = 'url=' + thisUrl + '&item_id=' + item_id;
	new Ajax.Updater( d,
		url,
		{method: 'get', parameters: params,evalScripts:true}
	);
}

function sDislike( thisUrl, item_id ) {
    $$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });
    $( 'tPagerate' ).show();

	var d = $( 'stabc-pagerate' );
	var url = '/pagerate/hate';
	
	var params = 'url=' + thisUrl + '&item_id=' + item_id;
	new Ajax.Updater( d,
		url,
		{method: 'get', parameters: params, evalScripts:true}
	);
}

function sUpdatePageRate( like, dislike ) {
	$( 'rateMe' ).update('<a href="javascript:void(0);" class="tab-3">'+parseInt(like)+'</a>'+'<a href="javascript:void(0);"  class="tab-4">'+parseInt(dislike)+'</a>');

}

function sHighScore(game,gamescorelist,refreshed) {
	
	var params = 'g=' + game;
	
	if (refreshed) {
		if (gamescorelist=='top10') {
				new Ajax.PeriodicalUpdater('highscore-top10', '/flashoyunlar/top10', {
				  method: 'get', frequency: 60, parameters: params
				});
			}
		}
	else {
		if (gamescorelist=='top10') {
			$('highscore-top10').show();$('highscore-top100').hide();
			new Ajax.Updater('highscore-top10', '/flashoyunlar/top10', {
				  method: 'get', parameters: params});
		}
		if (gamescorelist=='top100') {
			$('highscore-top10').hide();$('highscore-top100').show();
			new Ajax.Updater('highscore-top100', '/flashoyunlar/top100', {
				  method: 'get', parameters: params});
		}
	
	}
}

function sSocial() {
	$$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });
	$('tSocial').show();
}

function sSendFriend(thisUrl) {

	$$( '.tsBoxes' ).each( function ( n ) {
        n.hide();
    });

	$('tSendFriend').show();

	
	var d = $( 'stabc-send' );
	var url = '/share/send';
	
	
	
	var params = 'url=' + thisUrl + '&r=' + parseInt(Math.random()*99999999);
	new Ajax.Updater( d,
		url,
		{method: 'get', parameters: params}
	);
}

function sendF() {
	var f = $( 'send-friend-form' );
	var params = f.serialize();
	f.disable();
	
	var d = $( 'stabc-send' );
	var url = '/share/send?r=' + parseInt( Math.random() * 99999999 ) ;
	
	new Ajax.Updater( d,
		url,
		{method: 'post', parameters: params}
	);
}

function shareLink(destSite , url){	
	var targetURL = "";
	
	switch (destSite){
		case "facebook":
			targetURL = "http://www.facebook.com/sharer.php?u=" + url;
		break;
	
		case "twitter":
			targetURL = "http://twitter.com/home/?status=" + url;
		break;
	
		case "friendfeed":
			targetURL = "http://friendfeed.com/share?url=" + url;
		break;
	}
	
	if(targetURL != ""){
		if(destSite == 'facebook') {
			popUp(targetURL);
		}
		else {
			window.open(targetURL , "_blank");
		}	
	}	
}

function shareLinkWithTitle(destSite , title , url){	
	var targetURL = "";
	
	switch (destSite){
		case "facebook":
			targetURL = "http://www.facebook.com/sharer.php?u=" + url + '&t=' + title;
		break;
	
		case "twitter":
			targetURL = "http://twitter.com/home/?status="+ title + " "+ url;
		break;
	
		case "friendfeed":
			targetURL = "http://friendfeed.com/share?url=" + url + "&title=" + title;
		break;
	}
	
	if(targetURL != ""){
		if(destSite == 'facebook') {
			popUp(targetURL);
		}
		else {
			window.open(targetURL , "_blank");
		}	
	}	
}

function shareThisPage(destSite){
	
	var title = "";	
	try {
		title = $("title").html();
	} catch( err ){
		title = "gnctrkcll";
	}		

	thisUrl = location.href;
	thisHost = document.location.host;
	thisExcept = "http://"+thisHost+"/muzik/";
	if  ( (document.location.hash.length>1) && (thisUrl.substr(0,thisExcept.length) == thisExcept ) ) {
		thisUrl="http://"+thisHost+"/muzik/"+document.location.hash.substr(1).replace("/muzik/","");
	}
	
	
	var targetURL = "";
	
	switch (destSite){
	case "facebook":
		targetURL = "http://www.facebook.com/sharer.php?u=" + thisUrl;
	break;

	case "twitter":
		targetURL = "http://twitter.com/home/?status="+ title + " "+ thisUrl;
	break;

	case "friendfeed":
		targetURL = "http://friendfeed.com/share?url=" + thisUrl + "&title=" + title;
	break;

	case "stumbleupon":
		targetURL = "http://www.stumbleupon.com/refer.php?url=" + thisUrl + "&title=" + title;
	break;

	case "eksenim":
		targetURL = "http://eksenim.mynet.com/ep/GuncellemeMode.aspx?ViewIndex=12&iadres=" + thisUrl + "&ibaslik=" + title;
	break;

	case "blogger":
		targetURL = "http://blogger.com";
	break;

	case "wordpress":
		targetURL = "http://wordpress.com";
	break;

	case "digg":
		targetURL = "http://digg.com/submit?url=" + thisUrl + "&title=" + title;
	break;

	case "delicious":
		targetURL = "http://del.icio.us/post?url=" + thisUrl + "&title="+ title;
	break;

	case "google":
		targetURL = "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + thisUrl  + "&title=" + title;
	break;

	case "yahoo":
		targetURL = "http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=" + thisUrl + "&title="+ title;
	break;

	case "myspace":
		targetURL = "http://www.myspace.com/Modules/PostTo/Pages/?c="+ thisUrl + "&t=" + title;
	break;

	case "live":
		targetURL = "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=" + thisUrl + "&title="+ title;
	break;

	case "oyyla":
		targetURL = "http://www.oyyla.com/gonder?url=" + thisUrl;
	break;

	case "tusul":
		targetURL = "http://www.tusul.com/submit.php?url=" + thisUrl;
	break;

	case "technorati":
		targetURL = "http://www.technorati.com/faves?add=" + thisUrl;
	break;

	case "reddit":
		targetURL = "http://reddit.com/submit?url=" + thisUrl + "&title=" + title;
	break;

	}
	if(targetURL != ""){
		window.open(targetURL,"_blank");
	}	
}


function popUp(url) {
	day = new Date();
	
	id = day.getTime();
	
	eval("page" + id + " = window.open(url , '" + id + "' , 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=400,left = 483,top = 184');");
}
