// water mark textfield
$(document).ready(function() {
	$("a.login").fancybox({
		type: "iframe",
		width: 600,
		height: 287,
		padding: 0,
		margin: 0,
		centerOnScroll: true,
		scrolling : "no",
        onClosed: function() {
            parent.location.reload(true);
        }
  	});
	$("a.registration").fancybox({
		type: "iframe",
		width: 600,
		height: 529,
		padding: 0,
		margin: 0,
		centerOnScroll: true,
		scrolling : "no",
        onClosed: function() {
            parent.location.reload(true);
        }
	});
	$("a.verify").fancybox({
		type: "iframe",
		width: 600,
		height: 150,
		padding: 0,
		margin: 0,
		centerOnScroll: true,
		scrolling : "no"
  	});
	$("#content .music-list-holder .columns ul li:nth-child(2n+1)").css("background","#ececec");
	$(".cart tbody tr:nth-child(2n+1)").css("background","#ececec");
	$("#content .chart-holder .chart li:odd").css("background-color","#ececec");

	$("#keywords-field").attr("value","Search");
	$("#keywords-field").focus(function(){
		var fieldValue = this.value;
		if (fieldValue.toLowerCase() == "search") {
			this.value = "";
		}
	});
	
	$("#keywords-field").blur(function(){
		var fieldValue = this.value;
		if (fieldValue.toLowerCase() == "search" || fieldValue == "" || fieldValue == null) {
			this.value = "Search";
		}
	});

	/*
	$("a.registration").click(function() {
		var url = this.href;
		$().lightbox(url);
		return false;
	});
	$("a.login").click(function() {
		var url = this.href;
		$().lightbox(url);
		return false;
	});
	*/

	/* chart switching */
	$.fn.chartSwitch = function(chart) {
		
		if(chart == "bottom") {
			$(".chart ul.bottom").show('fast');
		} else if (chart == "top") {
			$(".chart ul.bottom").hide('fast');
		}

		$(".chart").fadeOut("fast",function() {
			$(this).fadeIn("fast");
		});
		$().stateSwitch(".chart-pagination a.active");
	}

	/* chart category switch */
	$.fn.switchCat = function(button) {
		if(!$(button).hasClass("active")) {
			$(".chart").fadeOut("fast",function() {
				$(this).fadeIn("fast");
			});
			$().stateSwitch(".chart-tabs a");
			$(button).addClass("active");
			return false;
		}
	}

	$.fn.stateSwitch = function(elem) {
		$(elem).removeClass('active');
	}
	
	var browserName = window.navigator.appCodeName;
	$(".browser").html(browserName);
	
	// lightbox script
	$.fn.lightbox = function(content) {
		$("#lightbox").remove();
		$("body").append("<div id='lightbox'></div>");
		$("#lightbox").css({"display":"none","height":$("#wrap").height()+"px"});
		// load lightbox content
		var cont = $.ajax({
			url : content,
			async : false,
		});
		$("#lightbox").html(cont['responseText']);
		// display lightbox
		$("#lightbox").fadeIn(400);
		$("#wrap").animate({opacity:0.2},400);
		// bind listener to close and cancel button
		$("#lightbox .heading a[href$='close'], #lightbox .cancel-btn").click(function() {
			$("#lightbox").fadeOut(400,function() {
				$("#lightbox").remove();
			});
			$("#wrap").animate({opacity:1},400);
		});
		// bind listener if mouse clicked outside the lightbox
		$("#lightbox").click(function(e) {
			var pos = $("#lightbox div:first-child").offset();
			var gapL = pos.left;
			var gapR = pos.left + $(".lightbox-data").width();
			var gapTop = pos.top;
			var gapBot = pos.top + $(".lightbox-data").height();
			
			if (e.pageX < gapL || e.pageX > gapR || e.pageY < gapTop || e.pageY > gapBot) {
				$("#lightbox").fadeOut(400,function() {
					$("#lightbox").remove();
				});
				$("#wrap").animate({opacity:1},400);
			}
		});
	}
});
