function newWin(nameImg,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open("","",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes');
	win.document.write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table cellpadding=0 cellspacing=0 border=0><tr><td><img src="'+nameImg+'" style="cursor:hand;" onclick="window.close();" alt=""></td></tr></table></body></html>');
  	win.document.close();
}

function newWinHtml(urlHtml,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open(urlHtml,"",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition);
}

function open_window(link,w,h) {
 LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 var win = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=no,location=no,scrollbars=yes,resizable=yes';
 newWin = window.open(link,'newWin'+w+h,win);
}

function procSubscribe(frm, proc, w, h) {
	ofrm = document.getElementById(frm);
	window.open('', frm, 'width='+w+',height='+h);
	eval("ofrm.subscribe_type.value="+proc);
	ofrm.submit();
}

function procFocus(ob, txt) {
	if (ob.value == txt) {
		ob.value = '';
	}	
}

function procBlur(ob, txt) {
	if (ob.value == '') {
		ob.value = txt;
	}	
}

document.onkeydown = register;

function register(e) {
	if (!e) e = window.event;
	var k = e.keyCode;
	if (e.ctrlKey) {
		var tagName = (e.target || e.srcElement).tagName;
		if (tagName != 'INPUT' && tagName != 'TEXTAREA') {
			var d;
			if (k == 37) {
				d = $('#previous_page');
			}
			if (k == 39) {
				d = $('#next_page');
			}
			if (d) location.href = d.attr('href');
		}
	}
}

/* Text cursor */
$(document).ready ( function(){
	$('#textCur').bind(
		'mouseover', function () {
			for(i = 0; i < 2; i++){
			  $("#textCur").animate({opacity: "hide"}, 1400);
			  $("#textCur").animate({opacity: "show"}, 400);
			}
		}
	)
});

/* projectPics */
$(document).ready(function (){
	var array_rand = function (arr){
		return Math.floor(arr.length * Math.random())
	}

    var shuffle = function (s){	// array shuffle
		if (s.length == 2) return new Array(s[1], s[0])
    	for (var times = s.length * 10, first, second, temp; times > 0; times--){
    		first  = array_rand(s)
			second = array_rand(s)
			temp = s[first], s[first] = s[second], s[second] = temp
		}
        return s
    }
    
    var get = function (prefix){
    	var s = new Array()
    	for (var i = 0;; i++ )
        if (document.getElementById(prefix+(i+1))){
            s[i] = new Array(
                document.getElementById(prefix+(i+1)).style.backgroundPosition,
                document.getElementById(prefix+'l_'+(i+1)).href
            )
        }
        else
        break;

		return s
    }
    
    var set = function (s, prefix)
    {
    	for (var i = 0; i<s.length; i++)
    	{
    		var y = parseInt(s[i][0].split(/ /)[0])+'px 0px'
    		$("#"+prefix+(i+1)).animate({backgroundPosition: y}, 1200)
            document.getElementById(prefix+'l_'+(i+1)).href = s[i][1]
    	}
    }

	// Small pics
    set(shuffle(get('sm_')), 'sm_')
	//Big Pics
    set(shuffle(get('big_')), 'big_')
	// Middle Pics
    set(shuffle(get('md_')), 'md_')
});


function switc(obj){
 if(document.getElementById){
 var el = document.getElementById(obj);
  if(el.style.display != "block"){
   el.style.display = "block";
  }else{
   el.style.display = "none";
  }
 }
}