//var server = 'http://www.sumopix.com/';


var cX = 0; var cY = 0; var rX = 0; var rY = 0;
underscore = {
    position: function (element) {
        var p = {x: element.offsetLeft || 0, y:element.offsetTop || 0};
        while (element = element.offsetParent) {
            p.x += element.offsetLeft;
            p.y += element.offsetTop;
        }
        return p;
    }
}

function HideContent(d) {
    if(d.length < 1) { return; }
    //document.getElementById(d).style.display = "none";
    $('#'+d).hide();
}

function ShowContent(d,sd) {


    if(d.length < 1) { return; }

    var left = parseInt( $('#'+sd).offset().left) + parseInt( $('#'+sd).width());
    var top = parseInt( $('#'+sd).offset().top) + parseInt( $('#'+sd).height());

     $('#'+d).css('left', left);
     $('#'+d).css('top', top);

/*
    var dd = document.getElementById(d);
    var ssd = document.getElementById(sd);
    //AssignPosition(dd);
    var p = underscore.position(ssd);
    dd.style.left = (p.x-100) + "px";
    dd.style.top = (p.y-70) + "px";
*/
    $('#'+d).show();


}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
//-->

// Jquery functions to hide and show browse images div
	$(document).ready(function () {
            $("a#single_image").fancybox({
                    'showCloseButton'	: true
            });
		$(".zia_class").hide(); //("The DOM is now loaded and can be manipulated.");

    /* ------------------- Toggle Blog_share script ----------------------- */
		$("#div_share_blog").hide();
		$("#blogforum_link").click(function() {
			$("#div_share_blog").toggle();
		});
                // Write COntents of HTMl LIke page
//                $('iframe').load(function() {
//                var theFrame = $("iframe", parent.document.body);
//                theFrame.height($(document.body).width() + 100);                    }
//                );
/* ------------------- Toggle Blog_ script ----------------------- */		// stop righ click function in the image

	//var tb_pathToImage="";
//	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox

  $("#banners_box").show();
    $("#banners_box").cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 4000
	});
/* ------------------- Tabs sCRIPT ----------------------- */
//   $("#tabs").tabs();
//   // set backimage for all tabs as close
//	init_tabs();
//	$( "#tabs" ).bind( "tabsselect", tab_click);
//	$( "#tabs" ).tabs( "option", "fx", { duration: 'fast', opacity: 'toggle' } );
/* ------------------- Tabs sCRIPT end----------------------- */


    //theRotator();
});

	function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});

	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);

}

function rotate() {
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

}

function toggle_upload(divid){
	//alert('Konkurrencen er slut, men der starter en ny konkurrencen igen inden for en måned. Tjek gerne tilbage igen');
	//return;
	var uploadid = "upload_div_" + divid;
	var buttonid = "part_edit_" + divid;
	document.getElementById(uploadid).style.display="";
	document.getElementById(buttonid).style.display="none";
}
function hide_upload(divid){
	//$(".zia_class").show(); //("The DOM is now loaded and can be manipulated.");
	//$("#"+divid).show(); //("The DOM is now loaded and can be manipulated.");
	var uploadid = "upload_div_" + divid;
	var buttonid = "part_edit_" + divid;
	document.getElementById(uploadid).style.display="none";
	document.getElementById(buttonid).style.display="";

	//$("div[id='upload_div_'+divid]").show();
}
function resetstar(){ // to reset all stars in grey color
	setRate(-1);
	setDescriptor(0);
}
  function tab_click(e,ui){
	 var tab_ind = ui.index + 1;

	 //alert('I am here');

    for(var i=0; i<=$('#tabs').tabs('length'); i++){
        var tab_ind = i + 1;
        var bgimage='http://www.sumopix.com/images/misc/tab_1_close.png';
        $('#tab-' + tab_ind).css('background', 'none'); // First set emptyimge
        $('#tab-' + tab_ind).css('background', 'url(' + bgimage + ')');
    }
	 var tab_ind = ui.index + 1;
	 var bgimage='http://www.sumopix.com/images/misc/tab_1.png';
	 $('#tab-' + tab_ind).css('background', 'none'); // First set emptyimge
	 $('#tab-' + tab_ind).css('background', 'url(' + bgimage + ')');

  }
  function init_tabs(){
  	//set background image for all tabs
 	for(var i=0; i<=$('#tabs').tabs('length'); i++){
	 var tab_ind = i + 1;
	 var bgimage='http://www.sumopix.com/images/misc/tab_' +  tab_ind + '_close.png';
	 $('#tab-' + tab_ind).css('background', 'none'); // First set emptyimge
	 $('#tab-' + tab_ind).css('background', 'url(' + bgimage + ')');
	}
	$('#tabs').tabs( 'select' , 0 );
	var $tabs = $('#tabs').tabs();
	// to select tab initially
	$tabs.tabs('select', $('#tab_sel').val()); // => 0

	var selected = $tabs.tabs('option', 'selected'); // => 0
	selected = selected + 1;
	 var bgimage='http://www.sumopix.com/images/misc/tab_' +  selected + '.png';
	 $('#tab-' + selected ).css('background', 'none'); // First set emptyimge
	 $('#tab-' + selected ).css('background', 'url(' + bgimage + ')');
  }
function change(n){
	setRate(n);
	setDescriptor(n+1);
}
function setDescriptor(n){
	switch(n){
		case 1:
			txt = "dårligt";
			break;
		case 2:
			txt = "rimeligt";
			break;
		case 3:
			txt = "godt";
			break;
		case 4:
			txt = "rigtig godt";
			break;
		case 5:
			txt = "helt i top";
			break;
		default:
			txt = "";
			break;
	}
	document.getElementById("star_descriptor").innerHTML = txt;
}

function rate(n){ // number of rating star
	//alert('Konkurrencen er slut, men der starter en ny konkurrencen igen inden for en måned. Tjek gerne tilbage igen');
	//return;
	var rating_starts  = n + 1 ;
	with(document){
		getElementById("frm_rating_star").value = rating_starts;
		getElementById("frm_rating").submit();
	}
}

function ajax_rate(n, comp_id){ // Ajax Rating
	var rating_starts  = n + 1;
	var server_my = 'http://www.sumopix.com/';	// Requestthrough ajax to a file and then respond if any
////////////////////////////////////////77
			//$('#stars_row').hide();
			//$("#stars_row").html("Rating er i gang......vent venligst");

			with(document){
				getElementById("frm_rating_star").value = rating_starts;
			}

			$.post(server_my + "ajax_image_rate.php",{
			   action: 'rate',
			   rating_star: '2'
			  }, function(xml){
                     $(xml).find('label').each(function(){
                         var result = $(this).find('result').text();
                         var message = $(this).find('message').text();
						// as we have gotten data now chec kwhat to display
						$('#stars_row').html("I am here");
                    }); //close each(
			  },
			  "xml");
/////////////////////////////////////77777

}

function setRate(n){ // number of rateing star
	var server_my = 'http://www.sumopix.com/';	// Requestthrough ajax to a file and then respond if any

	var star_icon = "";
	for(var i=n; i>=0; i--){
		document.getElementById("image_on[" + i +"]").src = server_my + 'images/icons/star_red.jpg';
	}
	for(i=4; i>n; i--){
		document.getElementById("image_on[" + i +"]").src = server_my + "images/icons/star_grey.jpg";
	}
	//alert(n);
}
function pop_up(act, id, val, pageNum, cat_id ){ //url, id, win_name

	//alert('Konkurrencen er slut, men der starter en ny konkurrencen igen inden for en måned. Tjek gerne tilbage igen');
	//return;


	//alert("YOu are here new login window");
	if(act == 'rate'){ // set tting rating start values and then popup and in popup subiithing parent window rating form....and close child ...
		document.getElementById("frm_rating_star").value = val;
	}
	if(act == 'comm'){
		val = document.getElementById("post_comment").value; // value is already setted
	}

	var winobj = window.open("http://www.sumopix.com/scripts/php/login_comp.php?act=" + act + "&id=" + id + "&val=" + val + "&pageNum=" + pageNum + "&cat_id=" + cat_id,"wnd_popup","menubar=no,width=430,height=245,toolbar=no");
//	var winobj = window.open("http://www.sumopix.com/scripts/php/login_comp.php?act=" + act + "&id=" + id + "&val=" + val,"wnd_popup","menubar=no,width=430,height=230,toolbar=no");
//	document.getElementById("frm_popup").target=winobj;

}
function popup_win( ){ //url, id, win_name
	var winobj = window.open("http://www.sumopix.com/scripts/php/feedback.php","wnd_popup","menubar=no,width=460,height=300,toolbar=no,top=300,left=300");
}
//setRate(1);
<!--
// Nannette Thacker http://www.shiningstar.net
function confirmSubmit(title)
{
var agree=confirm(title);
if (agree)
	return true ;
else
	return false ;
}
// -->

function beforeUpload(id, action_do){
	var flag=true;
	var a = $('#image_' + id).val();
	if(action_do == 'edit_image'){ // wants to edit an image
                if( $('#title_' + id).val() == "" ){
                        alert('Venligst indtast en titel');
			flag = false;
                }
                else if( $('#desc_' + id).val() == "" ){
                        alert('Venligst indtast en beskrivelse');
			flag = false;
                }
//                return flag;
	}else{ // check whether some image is selected or not if yes whats the image type....
		// accessing image field of the form
		/*if( frm.image.value.lastIndexOf(".jpg") == -1 )
			alert("Invalid format");*/
		//alert(a.length);
		if(a == ""){ // want to overwrite some image in competition
			alert("Ugyldigt billedformat");
			flag = false;
		}
                else if( $('#title_' + id).val() == "" ){
                        alert('Venligst indtast en titel');
			flag = false;
                }
                else if( $('#desc_' + id).val() == "" ){
                        alert('Venligst indtast en beskrivelse');
			flag = false;
                }
		var ext = a.substring(a.lastIndexOf('.') + 1);
		if( !(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" ||  ext == "PNG") )
		{
			//alert("Ugyldigt billedformat");
			flag = false;
		}
	}
        return flag;
}

function beforePostComment(frm, val){
	if(frm.post_comment.value == "" || frm.post_comment.value == val){
		alert("Skriv Kommentar");
		frm.post_comment.focus();
		return false;
	}else
		return true;
}

