var GalleryId = 0;
var Micro = 0;
var artistid =0;
var gallerylimit=4;
$(document).ready(function(){
	/* Afto ine gia to newsticker */
	/* Afto ine gia to pngFix se IE 5.5 & 6 */
  	try{
		$(document).pngFix();
		correctPNG();
	}catch(e){}
	//Moutsatsos PNG Fix mpike sto footer tis selidas
	
  	/** Create of tabls **/
  	//$('#container').tabs();
  	//get the cookie and change the background if any cookie exists!
  	//var col = $.cookie('mad_bg_color');
	//if (col){
		//document.bgColor = col;
//		chdoc(col);
  	//}
	
	// slider
	// h function testForObject elegxei an yparxei to #id toy div. Gia na mi xtipaei o browser
	var o = testForObject("madslidepromo");
	if (o) {
		$('ul#madslidepromo').innerfade({
										speed: 1000,
										timeout: 3000,
										type: 'sequence',
										containerheight: '216px'
		});
	}
	
	
if (GalleryId||artistid){
	GetImages();
}

$("#UserControl").load("/libs/User.php");


 });
 
function GetImages(){
	if (artistid){
		var galleryurl = "/libs/photogallery/artistImages.php";
	}else{
		var galleryurl = "/libs/photogallery/gallery.php";
	}
	$.ajax({type: "POST",dataType: "xml",url: galleryurl ,data: "id="+GalleryId+"&m="+Micro+"&artistid="+artistid+"&limit="+gallerylimit,success: function(xml){
				var html = '<div style=" float:left; margin: 0 0 20px 0; padding:0 0 0 20px;">';
				$(xml).find('image').each(function(){
					var imgID = $(this).attr('id');
					var galID = $(this).attr('gallery');
					var imgSrc = $(this).find('path').text();
					var width = $(this).find('width').text();
					var height = $(this).find('height').text();
					html +='<div class="photo_gallery_thumb_box">&nbsp;<a href="/gallery/?alb='+galID+'&id='+imgID+'&KeepThis=true&TB_iframe=true&height=588&width=719&cap=1" class="thickbox">';
					if (height>80){
						html +='<img src="'+imgSrc+'" border="0" height="80"/>';
					}else if (width>80){
						html +='<img src="'+imgSrc+'" border="0" width="80"/>';
					}else{
						html +='<img src="'+imgSrc+'" border="0"/>';
					}
					html +='</a>&nbsp;</div>';
				});
				html +='</div>';
				$("#gallery_thumbs").html(html);
				tb_init("a.thickbox");
			
		}
	});
}
 
function LoadGallery(id){
	document.write('<div id="gallery_thumbs"><img src="/skin/mad/ajax/loading.gif" border="0" /></div>');
	if(id){
		GalleryId = id;
	}
	return true;
}
 
function GetLiveTV(){
	return false;
	$("#LiveTV").html(" ");
	$.get(
		"/libs/LoadTV.php", {}, function(data)
		{
			$("#LiveTV").append(data);
			//$("#LiveTV").append(data).find("ul").newsTicker();
		}
	)
	//setTimeout("GetLiveTV()",10000);
}

function GetLiveRadio(){
	return false;
	$("#LiveRadio").html(" ");
	$.get(
		"/libs/LoadRadio.php", {}, function(data)
		{
			$("#LiveRadio").append(data);
			//$("#LiveRadio").append(data).find("ul").newsTicker();
		}
	)
	//setTimeout("GetLiveRadio()",10000);
}
  
function chdoc(color){
 	var COOKIE_NAME = 'mad_bg_color';
    // set cookie by number of days
    $.cookie(COOKIE_NAME, color , { path: '/', expires: 1 });
    var pic = $("body").css("background-image");
    $("body").css("background",color+" "+pic);
}
function print(id,catid,width,height){
	 var w = screen.width;
	 var h = screen.height;
	 w = (w-width)/2
	 h = (h-height)/2
	 win = window.open ("/print.php?id="+id+"&c="+catid,"Print","status=0,toolbar=0,location =0,menubar=0,directories=0,resizable=1,scrollbars =1,height="+height+",width="+width+",left="+w+",top="+h);
}
function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function SubmitComment(){
	var msg = "Θα πρέπει να συμπληρώσετε  \n";
	var e = false;
	if (!document.frmComment.firstname.value){
		msg += " το όνομά σας\n";
		e = true;
	}
	if (!document.frmComment.email.value){
		msg += " το E-mail σας\n";
		e = true;
	}
	if (!document.frmComment.message.value){
		msg += " το Μήνυμα σας\n";
		e = true;
	}
	if (e){
		alert(msg+" και μετά να πατήσετε το: Οκ τα είπα!");
	}else{
		document.frmComment.submit();
	}
}

function AjaxSubmitComment(formname){
	if (!formname) return false;
		$("#site_submit").attr("value","Παρακαλώ περιμένετε...").attr("disabled","disabled");
		var s = $("#"+formname).serialize();
		$.post("/nc/process.php?do=writeCommentAjax", s,
		function(data){
			var tmp = data.split("##");
			if (tmp[0]=="e"){
				$("#response").html(tmp[1]);
				$("#site_submit").attr("value"," ΔΗΜΟΣΙΕΥΣΗ ").removeAttr("disabled");
				$("#response").show();
				setTimeout('$("#response").hide("slow");',4000);
			}else{
				var start = new Date();
				$("#imgimage").attr("src","http://www.mad.tv/nc/imgcode/code.php?t="+start.getTime());
				$("#response").html(data);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',4000);
				//$("#firstname").val("");
				//$("#email").val("");
				$("#imgcode").val("");
				$("#message").val("");
				$("#site_submit").attr("value"," ΔΗΜΟΣΙΕΥΣΗ ").removeAttr("disabled");
			}
		});
	//}
	try{
		if (tmp[0]!="e"){
			setTimeout("LoadAjaxComments()",250);
		}
	}catch(e){/*alert(e);*/}
	return false;
}

function AjaxSubmitComment_yourtop(formname){
	if (!formname) return false;
	if ($("#firstname").val() && $("#message").val()) {
		var s = $("#"+formname).serialize();
		$.post("/nc/microsites/yourvoice/process.php?do=writeCommentAjax_yourtop", s,
		function(data){
			var tmp = data.split("##");
			if (tmp[0]=="e"){
				$("#response").html(tmp[1]);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);
			}else{
				var start = new Date();
				$("#response").html(data);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);
			}
          /*$("#firstname").val() = "";
            $("#message").val() = "";
           */
           $("#firstname").val("");
           $("#message").val("");
		});
	}
    else {
        $("#response").html("Συμπληρώστε όνομα & μύνημα");
       	$("#response").show();
        setTimeout('$("#response").hide("slow");',3000);
    }
   	try{
		if (tmp[0]!="e"){
			setTimeout("LoadAjaxComments()",250);
		}
	}catch(e){/*alert(e);*/}
	return false;
}

function AjaxSubmitComment_kesha(formname){

	if (!formname) return false;
    var tmp;
    if ( ($("#firstname").val()) && ($("#message").val()) && ($("#email").val()) ) {
		var s = $("#"+formname).serialize();
		$.post("/nc/microsites/kesha/process.php", s,
		function(data){
			tmp = data.split("##");
			if (tmp[0]=="e"){
				$("#response").html(tmp[1]);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);
			}else{
				var start = new Date();
				$("#response").html(data);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);

               $("#firstname").val("");
               $("#email").val("");
               $("#message").val("");

           }//else
		});
	}
    else {
        $("#response").html("Συμπληρώστε όνομα & email & μύνημα");
       	$("#response").show();
        setTimeout('$("#response").hide("slow");',3000);
    }
//   	try{
//	    setTimeout("LoadAjaxComments()",250);
//	}catch(e){alert(e);}
	return false;
}


function AjaxSubmitComment_paparizou(formname){
	if (!formname) return false;
	if ($("#firstname").val() && $("#message").val()) {
		var s = $("#"+formname).serialize();
		$.post("/nc/microsites/paparizou/process.php", s,
		function(data){
			var tmp = data.split("##");
			if (tmp[0]=="e"){
				$("#response").html(tmp[1]);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);
			}else{
				var start = new Date();
				$("#response").html(data);
				$("#response").show();
				setTimeout('$("#response").hide("slow");',3000);
			}
          /*$("#firstname").val() = "";
            $("#message").val() = "";
           */
           $("#firstname").val("");
           $("#message").val("");
		});
	}
    else {
        $("#response").html("Συμπληρώστε όνομα & σχόλιο");
       	$("#response").show();
        setTimeout('$("#response").hide("slow");',3000);
    }
   	try{
		if (tmp[0]!="e"){
			setTimeout("LoadAjaxComments()",250);
		}
	}catch(e){/*alert(e);*/}
	return false;
}













function AjaxSubmitCommentAction(formname){
	if (!formname) return false;
        var tmp =null;
        $("#site_submit").attr("value","Παρακαλώ περιμένετε...").attr("disabled","disabled");
		var s = $("#"+formname).serialize();
		var action = $("#"+formname).attr("action");
		if (!action) action="/nc/process.php?do=writeCommentAjax";
		$.post(action, s,
  		function(data){
  			tmp = data.split("##");
  			if (tmp[0]=="e"){
  				$("#response").html(tmp[1]);
  				$("#site_submit").attr("value"," ΔΗΜΟΣΙΕΥΣΗ ").removeAttr("disabled");
  				$("#response").show();
  				setTimeout('$("#response").hide("slow");',4000);
  			}else{
 				var start = new Date();
  				$("#imgimage").attr("src","http://www.mad.tv/nc/imgcode/code.php?t="+start.getTime());
  				$("#response").html(data);
  				$("#response").show();
  				setTimeout('$("#response").hide("slow");',4000);
  				//$("#firstname").val("");
  				//$("#email").val("");
  				$("#imgcode").val("");
  				$("#message").val("");
  				$("#site_submit").attr("value"," ΔΗΜΟΣΙΕΥΣΗ ").removeAttr("disabled");
  			}
            try{
        		if (tmp[0]!="e"){
        			setTimeout("LoadAjaxComments()",250);
        		}
        	}catch(e){alert(e);}
  		});
	return false;
}

function ReloadCode(){
	var start = new Date();
	$("#imgimage").attr("src","http://www.mad.tv/nc/imgcode/code.php?t="+start.getTime());
	return true;
}

function CheckMail()
{
	apos=document.frmComment.email.value.indexOf("@");
	dotpos=document.frmComment.email.value.lastIndexOf(".");
	if (document.frmComment.email.value == "" || apos<1 || dotpos-apos<2){
		document.frmComment.email.focus();
		return false
	}
	return true
}


var wimpySwf = "http://www.mad.tv/libs/button.swf";
var wimpyConfigs="&playingColor=e6e6e6&arrowColor=686868&grinderColor=3F9600&theBkgdColor=eaeaea&rollOverColor=bcbcbc";
function showbutton(str){
	var myid = Math.round((Math.random()*1000)+1);
	var flashCode = "";
	var newlineChar = "\n";
	flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,47,0" width="30" height="30" id="wimpybutton'+myid+'">'+newlineChar;
	flashCode += '<param name="movie" value="'+wimpySwf+'" />'+newlineChar;
	flashCode += '<param name="loop" value="false" />'+newlineChar;
	flashCode += '<param name="menu" value="false" />'+newlineChar;
	flashCode += '<param name="quality" value="high" />'+newlineChar;
	flashCode += '<param name="wmode" value="opaque" />'+newlineChar;
	flashCode += '<param name="flashvars" value="theFile='+str+wimpyConfigs+'" />'+newlineChar;
	flashCode += '<embed src="'+wimpySwf+'" width="30" height="30" flashvars="theFile='+str+wimpyConfigs+'" wmode="transparent" loop="false" menu="false" quality="high" name="wimpybutton'+myid+' align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'+newlineChar;
	document.write(flashCode);
}

function testForObject(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o)
  {
    if (Tag)
    {
      if (o.tagName.toLowerCase() == Tag.toLowerCase())
      {
        return o;
      }
    }
    else
    {
      return o;
    }
  }
  return null;
}

function getXY(obj)
{
  var curleft = 0;
  var curtop = obj.offsetHeight + 5;
  var border;
  if (obj.offsetParent)
  {
    do
    {
      // XXX: If the element is position: relative we have to add borderWidth
      if (getStyle(obj, 'position') == 'relative')
      {
        if (border = _pub.getStyle(obj, 'border-top-width')) curtop += parseInt(border);
        if (border = _pub.getStyle(obj, 'border-left-width')) curleft += parseInt(border);
      }
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    }
    while (obj = obj.offsetParent)
  }
  else if (obj.x)
  {
    curleft += obj.x;
    curtop += obj.y;
  }
  return {'x': curleft, 'y': curtop};
}


