function clear_field(field,name)
{
		if(field.value==name){
			field.value="";
		}
}

function initRollOver (from_id) {

	$('#'+from_id+' img').each(function(){
		this.nimg = this.src;
		this.oimg = this.nimg.replace(/\.gif/i,'_o.gif');
		$(this).hover(
			function(){
				this.src = this.oimg;
			},
			function(){
				this.src = this.nimg;
			}
		);
	});
}


//<a> Roll over an change image from a tag

function initRollOver_Images (from_id) {
	$(from_id).each(function(){
		var img = $('img[@alt=\'ForJSRoll\']',this).get(0);
		if(!img) {return;}
		this.img = img;
		
		this.img.nimg = img.src;
		this.img.oimg = img.nimg.replace(/\.gif/i,'_o.gif');
		$(this).hover(
			function(){
				this.img.src = this.img.oimg;
			},
			function(){
				this.img.src = this.img.nimg;
			}
		);
	});
}

function noSelect(el,cursor) {
	var elements = $(el);
	elements.each(function(){
		this.onselectstart = function() {
	        return false;
	    };
	    this.unselectable = "on";
	    this.style.MozUserSelect = "none";
	    if(cursor) {
	    	this.style.cursor = cursor;
	    }else{
	    	this.style.cursor = "default";
	    }
    })
}

function str_replace ( search, replace, subject ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
 
    var result = "";
    var prev_i = 0;
    for (i = subject.indexOf(search); i > -1; i = subject.indexOf(search, i)) {
        result += subject.substring(prev_i, i);
        result += replace;
        i += search.length;
        prev_i = i;
    }
 
    return result + subject.substring(prev_i, subject.length);
}

function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = haystack.indexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}

function enableLargeImages() {        
    $("img[src^='/assets/']").each(function(){
        var x = $(this).attr('src');     
        if (strpos(x,'/stories/')==false && strpos(x,'/press/')==false && strpos(x,'/news/')==false
            && strpos(x,'/locations/')==false && strpos(x,'/links/')==false && strpos(x,'/gallery/')==false) {                    
            //$(this).replaceWith("<a href=\"/images/content_mari/"+str_replace('/assets/','',$(this).attr('src'))+"\" class=\"thickbox\"><img src=\""+$(this).attr('src')+"\" /></a>");			
			$(this).replaceWith('<a href="" onclick="zoom(\'/images/content_mari/'+str_replace('/assets/','',$(this).attr('src'))+'\');return false;\"><img src="'+$(this).attr('src')+'" /></a>');
        }
    });
	$("img[src^='http://www.regiuneavest.ro/assets/']").each(function(){
        var x = $(this).attr('src');     
        if (strpos(x,'/stories/')==false && strpos(x,'/press/')==false && strpos(x,'/news/')==false
            && strpos(x,'/locations/')==false && strpos(x,'/links/')==false && strpos(x,'/gallery/')==false) {                    
            //$(this).replaceWith("<a href=\"/images/content_mari/"+str_replace('/assets/','',$(this).attr('src'))+"\" class=\"thickbox\"><img src=\""+$(this).attr('src')+"\" /></a>");			
			$(this).replaceWith('<a href="" onclick="zoom(\'/images/content_mari/'+str_replace('http://www.regiuneavest.ro/assets/','',$(this).attr('src'))+'\');return false;\"><img src="'+$(this).attr('src')+'" /></a>');
        }
    });
   
	$("a[class='thickbox']").each(function(){
        var x = $(this).attr('href');     
		var y = $(this).html();
        $(this).replaceWith('<a href="'+x+'" onclick="zoom(\''+x+'\');return false;\">'+y+'</a>');
        
    });
}

function zoom(img) {
	var width = 100;
	var height = 100;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var win = window.open('/zoom.php?img='+img,'ZOOM','scrollbars=auto,left='+left+',top='+top+',width='+width+',height='+height+',resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0');
	win.focus();
}

$(document).ready(function(){
	//init menus
	//initRollOver('countries');
	initRollOver('menu');
	
	initRollOver_Images('.black_box a');
	initRollOver_Images('.cities a');
	
	//disable selection
	noSelect('#noutati p','pointer');
	noSelect('#content_title','default');
	noSelect('#product_path','default');
	noSelect('.black_box a','pointer');
	noSelect('.black_box .title','default');
	noSelect('.black_box','default');
	noSelect('#footer','default');
	noSelect('.menu_and_copy .menu','pointer');
	
	enableLargeImages();
});