//ONLOAD ACTIONS
function onLoad() {
	//MOUSEOVER-OUT
	$(".tab").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".albumpicture").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".albumname").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".itemArtist").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".itemAlbum").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".albumname").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".itemArtist").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".itemAlbum").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$("#searchautocomplate").live("mouseover", function () {
		$("#searchautocomplate").removeClass("hide");
	});
	$("#searchautocomplate").live("mouseout", function () {
		$("#searchautocomplate").addClass("hide");
	});
	$(".song").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".artist").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".pagenumber").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".pagenumberalbum").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".pagenumberartist").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".pagenumbersong").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".pagenumberalbum").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".pagenumberartist").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".pagenumbersong").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".devamBtn").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".dvm").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".album_nav_left").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".album_nav_right").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".artistname").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).addClass("underline");
	});
	$(".artistname").live("mouseout", function () {
		$(this).removeClass("hand");
		$(this).removeClass("underline");
	});
	$(".artistname").live("mouseout", function () {
		$(this).removeClass("underline");
	});
	$(".data").live("mouseover", function () {
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".resultSong").live("mouseover", function () {
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".resultSong").live("mouseout", function () {
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".data").live("mouseout", function () {
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".dataringtone").live("mouseover", function () {
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".dataringtone").live("mouseout", function () {
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".dataringtoneforDataCat").live("mouseover", function () {
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".dataringtoneforDataCat").live("mouseout", function () {
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".albumsongrow").live("mouseover", function () {
		$(this).addClass("hand");
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".albumsongrow").live("mouseout", function () {
		$(this).addClass("hand");
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".kategoriler_left_text").live("mouseover", function () {
		$(this).addClass("whitetext");
		$(this).addClass("hand");
	});
	$(".kategoriler_left_text").live("mouseout", function () {
		$(this).removeClass("whitetext");
		
	});

	
	//MOUSEOVER-OUT FINISHED
	
	//MOUSE CLICK
	$(".artistname").live("click", function () {
		var artistid = $(this).attr("artistid");
		var artistname = $(this).attr("artistname");
		artistsubmit(artistid, artistname);
	});
	$(".itemArtist").live("click", function () {
		var artistid = $(this).attr("artistid");
		var artistname = $(this).attr("artistname");
		$("#searchautocomplate").addClass("hide");
		artistsubmit(artistid, artistname);
	});
	$(".album_nav_right").live("click", function () {
		var nextalbumid = $(this).attr("nextalbumid");
		var artistname = $(this).attr("artistname");
		gotoalbum(nextalbumid, "", artistname);
	});
	$(".album_nav_left").live("click", function () {
		var prevalbumid = $(this).attr("prevalbumid");
		var artistname = $(this).attr("artistname");
		gotoalbum(prevalbumid, "", artistname);
	});
	$(".tab").live("click", function () {
		closeSearchAutoComplate();
		var tabsname = $(this).parent().attr("id");
		var serviceid = $(this).attr("serviceid");
		var categoryid = $(this).attr("categoryid");
		var stylewidth = $(this).parent().attr("stylewidth");
		var styleheight = $(this).parent().attr("styleheight");
		var tabcontentname = tabsname + "content";
		$("#" + tabsname + "").children(".tab").removeClass("sel");
		$(this).addClass("sel");
		if (serviceid == "101" || serviceid == "102" || serviceid == "103" || serviceid == "104") {
			openstaticactions(serviceid);
		} else {
			indextabactions(serviceid, categoryid, tabcontentname, stylewidth, styleheight);
		}
	});
	$(".devamBtn").live("click", function () {
		closeSearchAutoComplate();
		window.scrollTo(0, 0);
		var categoryid = $(this).attr("categoryid");
		var serviceid = $(this).attr("serviceid");
		devamactions(categoryid, serviceid);
	});
	$(".albumpicture").live("click", function () {
		window.scrollTo(0, 0);
		var albumid = $(this).parent().attr("albumid");
		var albumname = $(this).parent().attr("albumname");
		var albumpicture = $(this).parent().attr("albumpicture");
		var artistname = $(this).parent().attr("artistname");
		var artistid = $(this).parent().attr("artistid");
		albumsubmit(albumid, albumname, albumpicture, artistname, artistid);
	});
	$(".albumname").live("click", function () {
		window.scrollTo(0, 0);
		var albumid = $(this).parent().parent().attr("albumid");
		var albumname = $(this).parent().parent().attr("albumname");
		var albumpicture = $(this).parent().parent().attr("albumpicture");
		var artistname = $(this).parent().parent().attr("artistname");
		var artistid = $(this).parent().parent().attr("artistid");
		albumsubmit(albumid, albumname, albumpicture, artistname, artistid);
	});
	$(".itemAlbum").live("click", function () {
		window.scrollTo(0, 0);
		var albumid = $(this).attr("albumid");
		var albumname = $(this).attr("albumname");
		var albumpicture = $(this).attr("albumpicture");
		var artistname = $(this).attr("artistname");
		var artistid = $(this).attr("artistid");
		$("#searchautocomplate").addClass("hide");
		albumsubmit(albumid, albumname, albumpicture, artistname, artistid);
	});
	$(".artist").live("click", function () {
		window.scrollTo(0, 0);
		var artistid = $(this).attr("artistid");
		var artistname = $(this).attr("artistname");
		artistsubmit(artistid, artistname);
	});
	$(".menu a").live("click", function () {
		closeSearchAutoComplate();
		var serviceid = $(this).parent().attr("serviceid");
		var categoryid = "2";
		if (serviceid == "-1") {
			return;
		} else {
			if (serviceid == "-2" || serviceid == "101" || serviceid == "111") {
				openstaticactions(serviceid);
			} else {
				if (serviceid == "99") {
					muzikactions(serviceid);
				} else {
					menuactions(categoryid, serviceid);
				}
			}
		}
	});
	$(".footer a").live("click", function () {
		closeSearchAutoComplate();
		window.scrollTo(0, 0);
		var serviceid = $(this).parent().attr("serviceid");
		var categoryid = "2";
		if (serviceid == "-1") {
			return;
		} else {
			if (serviceid == "-2" || serviceid == "-3" || serviceid == "-4" || serviceid == "101") {
				openstaticactions(serviceid);
			} else {
				if (serviceid == "99") {
					muzikactions(serviceid);
				} else {
					menuactions(categoryid, serviceid);
				}
			}
		}
	});
	$(".kategoriler_left_text").live("click", function () {
		closeSearchAutoComplate();
		var groupid = $(this).attr("groupid");
		var serviceid = $(this).attr("serviceid");
		var categoryid = $(this).attr("categoryid");
		var groupname = $(this).attr("groupname");
		window.scrollTo(0, 0);
		if (serviceid == 99) {
			muzikkategori(groupid, serviceid, categoryid, groupname);
		} else {
			tabContentData(groupid, serviceid, categoryid, groupname);
		}
	});
	$(".pagenumber").live("click", function () {
		var pagenr = $(this).attr("pagenr");
		var categoryid = $(this).attr("categoryid");
		var serviceid = $(this).attr("serviceid");
		var groupid = $(this).attr("groupid");
		pageactions(pagenr, categoryid, serviceid, groupid);
	});
	$(".pagenumbermuzikkategori").live("click", function () {
		var pagenr = $(this).attr("pagenr");
		var categoryid = $(this).attr("categoryid");
		var serviceid = $(this).attr("serviceid");
		var groupid = $(this).attr("groupid");
		pageactionsmuzikkategori(pagenr, categoryid, serviceid, groupid);
	});
	$(".pagenumberalbum").live("click", function () {
		var pagenr = $(this).attr("pagenr");
		var searchkeyword = $(this).attr("searchkeyword");
		if (searchkeyword != "null") {
			pageactionsSearch(pagenr, searchkeyword, "album");
		} else {
			if (searchkeyword == "null") {
				pageactionsMuzik(pagenr, "album");
			}
		}
	});
	$(".pagenumbersong").live("click", function () {
		var pagenr = $(this).attr("pagenr");
		var searchkeyword = $(this).attr("searchkeyword");
		if (searchkeyword != "null") {
			pageactionsSearch(pagenr, searchkeyword, "song");
		} else {
			if (searchkeyword == "null") {
				pageactionsMuzik(pagenr, "song");
			}
		}
	});
	$(".pagenumberartist").live("click", function () {
		var pagenr = $(this).attr("pagenr");
		var searchkeyword = $(this).attr("searchkeyword");
		if (searchkeyword != "null") {
			pageactionsSearch(pagenr, searchkeyword, "artist");
		} else {
			if (searchkeyword == "null") {
				pageactionsMuzik(pagenr, "artist");
			}
		}
	});
	$(".pagesagok").live("click", function () {
		var lastvisible = $(".pagingNav .visible:last").attr("id");
		var nextinvisible = parseInt(lastvisible) + 1;
		var firstvisible = nextinvisible - 6;
		$("#" + nextinvisible).removeClass("invisible");
		$("#" + nextinvisible).addClass("visible");
		$("#" + firstvisible).removeClass("visible");
		$("#" + firstvisible).addClass("invisible");
		$(".pagingNav .pagesolok").removeClass("invisible");
		$(".pagingNav .pagesolok").addClass("visible");
	});
	$(".pagesolok").live("click", function () {
		var lastvisible = $(".pagingNav .visible:last").attr("id");
		var firstinvisible = parseInt(lastvisible) - 5;
		if (lastvisible == 6) {
			$(".pagingNav .pagesolok").removeClass("visible");
			$(".pagingNav .pagesolok").addClass("invisible");
		}
		$("#" + firstinvisible).removeClass("invisible");
		$("#" + firstinvisible).addClass("visible");
		$("#" + lastvisible).removeClass("visible");
		$("#" + lastvisible).addClass("invisible");
	});
	$(".kategoriler_diger").live("click", function () {
		$("#invisiblekategoriler").removeClass("invisible");
	});
	
	//MOUSE CLICK FINISHED


//------------------
	//menu_top on mouse over action
	$("li").hover(function () {
		$(this).addClass("back");
	}, function () {
		$(this).removeClass("back");
	});
	
	//tab hand live function, hover is not used because for ajax generated part hover not working and we are using live with mouseover and mouseout seperately 
	$("a").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$("a").live("mouseout", function () {
		$(this).removeClass("hand");
	});
	$(".song").live("mouseover", function () {
		$(this).children(".tip").css("visibility", "visible");
	});
	$(".song").live("mouseout", function () {
		$(this).children(".tip").css("visibility", "hidden");
	});
	$(".albumler .album").live("click", function () {
		var albumid = $(this).attr("albumid");
		var albumpicture = $(this).attr("albumpicture");
		var albumname = $(this).attr("albumname");
		var artistname = $(this).attr("performername");
		albumactions(albumid, albumpicture, albumname, artistname);
	});
	$(".albumler .album").live("mouseover", function () {
		$(this).addClass("hand");
	});
	$(".content .devamBtn").live("click", function () {
		var categoryid = $(this).attr("categoryid");
		var serviceid = $(this).attr("serviceid");
		var clickedpage = $(this).attr("clickedpage");
		devamactions(categoryid, serviceid, clickedpage);
	});
	$(".content .devamBtn").live("mouseover", function () {
		$(this).addClass("hand");
	});	
	//paging actions
	$(".pagenumber").live("mouseover", function () {
		$(this).addClass("underline");
	});
	$(".pagenumber").live("mouseout", function () {
		$(this).removeClass("underline");
	});
	$(".test").live("click", function () {
		stopallmusic();
	});
}
//ONLOAD ACTIONS FINISHED

//METHODS
function ara() {
	var keyword = $("#search").attr("value");
	searchactions(keyword);
}
function stopallmusic() {
	var songamount = $(".albumsong .songamount").attr("amount");
	var flashid = new Array();
	var i = 0;
	for (i = 0; i < songamount; i++) {
		var flashobject = "flashobject_" + i;
		var iframeid = "ifrmminiplayer_" + i;
		var flashMovie = getFlashMovieObject(flashobject, iframeid);
		flashMovie.TGotoFrame("_root", 1);
	}
}
function getFlashMovieObject(movieName, iframeid) {
	var myIFrame = document.getElementById(iframeid);
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		return myIFrame.contentWindow.document.embeds[movieName];
	} else {
		return myIFrame.contentWindow.document.getElementById(movieName);
	}
}


//METHODS FINISHED


//AJAX METHODS
function openstaticactions(serviceid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"static.jsp", 
		data:"serviceid=" + serviceid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function indextabactions(serviceid, categoryid, tabcontentname, width, height) {
	waitmsg("#" + tabcontentname);
	$.ajax({
		type:"GET", 
		url:"tabcontent.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "&width=" + width + "&height=" + height + "", 
		success:function (msg) {
			onSuccess("#" + tabcontentname,msg);
	}});
}
function devamactions(categoryid, serviceid) {
	var url = "datakategoriler.jsp";
	if (serviceid == 20) {
		url = "albumler_list.jsp";
	} else {
		if (serviceid == 99) {
			url = "songs_list.jsp";
		}
	}
	waitmsg();
	$.ajax({type:"GET", url:url, data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "", success:function (msg) {
		onSuccess('',msg);
	}});
}
function menuactions(categoryid, serviceid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"datakategoriler.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function muzikactions(serviceid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"muzik.jsp", 
		data:"serviceid=" + serviceid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function muzikkategori(groupid, serviceid, categoryid, groupname) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"muzikkategoriler.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "&groupid=" + groupid + "&groupname=" + groupname + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function tabContentData(groupid, serviceid, categoryid, groupname) {
	waitmsg(".tabs ul");
	$.ajax({
		type:"GET", 
		url:"datakategoriler.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "&groupid=" + groupid + "&groupname=" + groupname + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function pageactions(pagenr, categoryid, serviceid, groupid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"datakategoriler.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "&pagenr=" + pagenr + "&groupid=" + groupid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function pageactionsmuzikkategori(pagenr, categoryid, serviceid, groupid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"muzikkategoriler.jsp", 
		data:"serviceid=" + serviceid + "&categoryid=" + categoryid + "&pagenr=" + pagenr + "&groupid=" + groupid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function pageactionsSearch(pagenr, searchkeyword, pageingarea) {
	var pagenralbum;
	var pagenrartist;
	var pagenrsong;
	if (pageingarea == "artist") {
		pagenrartist = pagenr;
		pagenrsong = "1";
		pagenralbum = "1";
	} else {
		if (pageingarea == "song") {
			pagenrsong = pagenr;
			pagenrartist = "1";
			pagenralbum = "1";
		} else {
			if (pageingarea == "album") {
				pagenralbum = pagenr;
				pagenrsong = "1";
				pagenrartist = "1";
			}
		}
	}
	var data = "pagenrAlbum=" + pagenralbum + "&pagenrArtist=" + pagenrartist + "&pagenrSong=" + pagenrsong + "&searchkeyword=" + searchkeyword + "";
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"search_result.jsp", 
		data:data, 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function pageactionsMuzik(pagenr, pageingarea) {
	var pagenralbum;
	var pagenrartist;
	var pagenrsong;
	if (pageingarea == "artist") {
		pagenrartist = pagenr;
		pagenrsong = "1";
		pagenralbum = "1";
	} else {
		if (pageingarea == "song") {
			pagenrsong = pagenr;
			pagenrartist = "1";
			pagenralbum = "1";
		} else {
			if (pageingarea == "album") {
				pagenralbum = pagenr;
				pagenrsong = "1";
				pagenrartist = "1";
			}
		}
	}
	var data = "pagenrAlbum=" + pagenralbum + "&pagenrArtist=" + pagenrartist + "&pagenrSong=" + pagenrsong + "";
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"muzik.jsp", 
		data:data, 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function submitphonebrand(b) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"static.jsp", 
		data:"b=" + b + "&serviceid=-4", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function submitphonebrandmodel(b, m) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"static.jsp", 
		data:"b=" + b + "&m=" + m + "&serviceid=-4", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function searchactions(searchkeyword) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"search_result.jsp", 
		data:"searchkeyword=" + searchkeyword + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function fillsearchresult(searchkey) {
	waitmsg("#searchautocomplate");
	$.ajax({type:"GET", 
		url:"searchautocomplate.jsp", 
		data:"searchkey=" + searchkey + "", 
		success:function (msg) {
			onSuccess("#searchautocomplate",msg);
	}});
}
function albumsubmit(albumid, albumname, albumpicture, artistname, artistid) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"album_detail.jsp", 
		data:"albumid=" + encodeURIComponent(albumid) + "&albumname=" + albumname + "&albumpicture=" + albumpicture + "&artistname=" + artistname + "&artistid=" + artistid + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function artistsubmit(artistid, artistname) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"artist_albums.jsp", 
		data:"artistid=" + artistid + "&artistname=" + artistname + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function gotoalbum(albumid, albumname, artistname) {
	waitmsg();
	$.ajax({
		type:"GET", 
		url:"album_detail.jsp", 
		data:"albumid=" + encodeURIComponent(albumid) + "&albumname=" + albumname + "&artistname=" + artistname + "", 
		success:function (msg) {
			onSuccess('',msg);
	}});
}
function flashopenalbum(albumid, artistname) {
	waitmsg();
	$.ajax({type:"GET", url:"album_detail.jsp", data:"albumid=" + encodeURIComponent(albumid) + "&artistname=" + artistname + "", 
	 success:function (msg) {
		onSuccess('',msg);
	}});
}
//AJAX METHODS FINISHED


function _isNothing(ufo) {
	return !ufo || typeof (ufo) == "undefined" || ufo.length <= 0 || ufo == "";
}

var waittext = "";
function waitmsg(obj) {
	document.body.style.cursor = 'wait';
	waittext = "<span class='waitmsg'>Lütfen Bekleyiniz...</span>";
	if (_isNothing(obj)) {
		$(".div_main").html(waittext);
	} else {
		$(obj).html(waittext);
	}
}

function logger(msg) {
	var thetime = new Date();
	$("#logLayer").html("Time:" + thetime.getHours() + ":" + thetime.getMinutes() + ":" + thetime.getSeconds() + "->" + msg + "<br />");
}

function closeSearchAutoComplate() {
	if($("#searchautocomplate"))
		$("#searchautocomplate").addClass("hide");
}

function onSuccess(obj,msg){
	if (_isNothing(obj)) {
		$(".div_main").html(msg);
	}else{
		$(obj).html(msg);
	}
	document.body.style.cursor = 'default';	
}

function setMainStyle(mainheigth, divmainheigth){
	$(".main_content_class").css('height',mainheigth);
	$(".div_main").css('height',divmainheigth);
}
