/*
	ivisited.net — Design functions
	
	Netstar 2011 (c)
*/

var site_left_point = window.innerWidth / 2 - 501;
var is_hold = false;

var viewportwidth;
var viewportheight;

function init()
{
	getViewportdimension();
}

function getViewportdimension()
{
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 	if (typeof window.innerWidth != 'undefined') {
 		viewportwidth = window.innerWidth,
 		viewportheight = window.innerHeight
 	}
 	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 	else if (typeof document.documentElement != 'undefined'
 		&& typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
 		viewportwidth = document.documentElement.clientWidth,
 		viewportheight = document.documentElement.clientHeight
 	}
 	// older versions of IE
 	else {
 		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
 		viewportheight = document.getElementsByTagName('body')[0].clientHeight
 	}
}

function getBounds(element)
{
	var left = element.offsetLeft;
	var top = element.offsetTop;
	for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function show_info_block(id, cx, cy)
{
	var src = document.getElementById(id);
	var coord = getBounds(id);
	src.style.top = cy + 'px';
	src.style.left = site_left_point + cx + 'px';
	src.style.display = 'block';
}

function hide_info_block(id)
{
	var src = document.getElementById(id);
	
	if(src !== null) {
		src.style.display = 'none';
	}
}

/*
function ge()
{
  var ea;
  for( var i = 0; i < arguments.length; i++ ) {
    var e = arguments[i];
    if( typeof e == 'string' ) e = document.getElementById(e);
    if( arguments.length == 1 ) return e;
    if( !ea ) ea = new Array();
    ea[ea.length] = e;
  }
  return ea;
}

function placeholderSetup(id, color)
{
	var el = ge(id);
	if(!el) return;
	if(el.type != 'text') return;
	if(el.type != 'text') return;
	
	var ph = el.getAttribute("placeholder");
	if( ph && ph != "" ) {
		el.value = ph;
		el.style.color = color;
		el.is_focused = 0;
		el.onfocus = placeholderFocus;
		el.onblur = placeholderBlur;
	}
}

function placeholderFocus()
{
  if(!this.is_focused) {
    this.is_focused = 1;
    this.value = '';

    var rs = this.getAttribute("radioselect");
    if( rs && rs != "" ) {
      var re = document.getElementById(rs);
      if(!re) { return; }
      if(re.type != 'radio') return;

      re.checked=true;
    }
  }
}

function placeholderBlur()
{
	var ph = this.getAttribute("placeholder")
	if( this.is_focused && ph && this.value == "" ) {
		this.is_focused = 0;
		this.value = ph;
		alert('Netstar');
	}
}
*/

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') window.onload = func;
	else window.onload = function() {
							if (oldonload) oldonload();
							func();
						 }
}

function windowOpener(windowUri, windowName, windowWidth, windowHeight)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}

function holdElement(obj)
{
	if(obj) {
		var width = $('#'+obj).width();
		var height = $('#'+obj).height();
		var top = $('#'+obj).offset().top + 1 + "px";
		var left = $('#'+obj).offset().left + 1 + "px";
	}
	else {
		var width = $(document).width();
		var height = $(document).height();
		var top = 0;
		var left = 0;
	}
	
	if(!is_hold) {
		$('#screen_holder').css({"display": "block", opacity: 0.7, "top":top,"left":left,"width":width,"height":height});
		is_hold = true;
	}
}

function unholdElement()
{
	if(is_hold) {
		$('#screen_holder').css({"display": "none"});
		is_hold = false;
	}
}

function openElement(obj_id)
{
	//$('#'+obj_id).show("slow");
	$('#'+obj_id).fadeIn("fast");
	return false;
}

function openElementPopup(obj_id, top, left, width, height)
{
	$('#'+obj_id).css({"top":top,"left":left,"width":width,"height":height,"position": 'absolute'});
	$('#'+obj_id).fadeIn("fast");
	return false;
}

function closeElement(obj_id)
{
	//$('#'+obj_id).hide("slow");
	$('#'+obj_id).fadeOut("fast");
	return false;
}



















this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

Array.prototype.count = function () {
	return this.length;
}

// starting the script on page load
$(document).ready(function(){
	init();
	imagePreview();
	
	
	
	
	
	
});


