// <![CDATA[
$(document).ready(function() {

    $(document).pngFix();
    /*$('li.headlink').hover(
	function() {
	    $('ul', this).css('display', 'block');
	},
	function() {
	    $('ul', this).css('display', 'none');
	});
    $('li.headlinkMiddle').hover(
	function() {
	    $('ul', this).css('display', 'block').hover(
		function() {
		    //console.info($(this).prev().attr("id"));
		    showCorrectBackGround($(this).prev().attr("id"));
		},
		function() {
		    resetBackGround();
		});
	},
	function() {
	    $('ul', this).css('display', 'none');
	});

    $('li.headlinkMiddle a').hover(
	function(){
	    showCorrectBackGround($(this).attr("id"));
	},
	function(){
	    resetBackGround();
	}
	);

    $('li.headlinkMiddle ul li').hover(
	function(){
	    showCorrectBackGround($(this).parent().prev().attr("id"));
	},
	function(){
	    showCorrectBackGround($(this).parent().prev().attr("id"));
	}
	);*/

    //uploadify
    $("#fisier").uploadify({
	'uploader'       : 'http://www.tiparprint.ro/assets/shared/swf/uploadify.swf',
	'script'         : 'http://www.tiparprint.ro/uploadify/uploadify.php',
	'cancelImg'      : '/assets/shared/images/cancel.png',
	'folder'         : '/',
	'auto'           : true,
	'multi'          : false,
	onError: function (a, b, c, d) {
	    if (d.status == 404)
		alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
	    else if (d.type === "HTTP")
		alert('error '+d.type+": "+d.status);
	    else if (d.type ==="File Size")
		alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
	    else
		alert('error '+d.type+": "+d.text);
	},
	onComplete: function(event, queueID, fileObj, reposnse, data) {
	    //adauga cu ajax chestia :-)
	    //$('input[name="poza_articol"]').val(fileObj.filePath);
	    $.post("http://www.tiparprint.ro/ajax/saveFile.html", {
		fileName: fileObj.filePath		
	    },
	    function(data){
		var dt = new Object;
		dt = eval(data);
		var htmlOutPut = "";
		var vr = false;
		for(key in dt){
		    vr = true;
		    $("#bdyFile tr").remove();
		    htmlOutPut += "<tr><td>" + dt[key].DataUpload + "</td><td>" + dt[key].FileUpload + "</td></tr>";
		    $("#bdyFile").append(htmlOutPut);
		//console.log(dt[key].ID);
		}

		if(!vr){$("#bdyFile tr").remove();}

	    });
	}
    });

    $("#termenCautare").Watermark("cauta un produs sau serviciu");
    $("#adresa_email").Watermark("Email");

});


function updateTable() {
    $.post("http://www.tiparprint.ro/ajax/getFiles.html",
	function(data){
	    var dt = new Object;
	    dt = eval(data);
	    var htmlOutPut = "";
	    var vr = false;
	    for(key in dt){
		vr = true;
		$("#bdyFile tr").remove();
		htmlOutPut += "<tr><td>" + dt[key].DataUpload + "</td><td>" + dt[key].FileUpload + "</td></tr>";
		$("#bdyFile").append(htmlOutPut);
	    //console.log(dt[key].ID);
	    }

	    if(!vr){$("#bdyFile tr").remove();}
	});
}

function showCorrectBackGround(htmlElId)
{
    htmlElSel = "#" + htmlElId;
    switch(htmlElId){
	case "publicitar":
	    $(htmlElSel).css('background-position','0px -110px');
	    break;
	case "office":
	    $(htmlElSel).css('background-position','-186px -110px');
	    break;
	case "albume":
	    $(htmlElSel).css('background-position','-372px -110px');
	    break;
	case "bannere":
	    $(htmlElSel).css('background-position','-558px -110px');
	    break;
	case "grafica":
	    $(htmlElSel).css('background-position','-744px -110px');
	    break;
    }
}

function resetBackGround()
{
    $("#publicitar").css('background-position','0px 0px');
    $("#office").css('background-position','-186px 0px');
    $("#albume").css('background-position','-372px 0px');
    $("#bannere").css('background-position','-558px 0px');
    $("#grafica").css('background-position','-744px 0px');
}

function changePicture(src, obj){
    $("#prezPict").attr("src", src);    
    $(".navPrez li a").attr("style", "color:#333; font-weight:normal");
    $(obj).attr("style", "color:red; font-weight:bold;");
}

// ]]>
