/* -------------------------------------------------------------------- */
/* Popup window
/* -------------------------------------------------------------------- */

var currentWindow

function popupWindow(win, winName, winWidth, winHeight, scrollbars){

	leftPos = 0; topPos = 0; // default variables for old browsers

	if (screen){ 
	
	    // checks specified parameters are not outside screen area
		if (winWidth>screen.width){
		   winWidth = screen.width;
		}
		
		if (winHeight>screen.height){
		   winHeight = screen.height - 55;
		}
		
		if (winWidth <= 0){
		   winWidth = screen.width;
		}
		
		if (winHeight <= 0){
		   winHeight = screen.height - 55;
		}
		
		// positions window by checking place parameter
		leftPos = screen.width/2 - winWidth/2;
		topPos = screen.height/2 - winHeight/2;
				
	}
	
	currentWindow = window.open(win,winName,'status=yes,toolbar=no,location=no,scrollbars='+ ((scrollbars)? 'yes' : 'no') +',resizable=yes,width='+winWidth+',height='+winHeight+',left='+leftPos+',top='+topPos+'');
	currentWindow.focus();
	
	return currentWindow;
}

/* -------------------------------------------------------------------- */
/* Preload Images
/* -------------------------------------------------------------------- */

var preloaded = new Array();
function preloadImages() {
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};

/* -------------------------------------------------------------------- */
/* Cross borwser attach event method
/* -------------------------------------------------------------------- */

function attachEventListener(obj, evt, fnc, useCapture){
	if (!useCapture) useCapture = false;
	if (obj.addEventListener){
		obj.addEventListener(evt, fnc, useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt, fnc);
	else{
		myAttachEventListener(obj,evt,fnc);
		obj['on'+evt] = function(){ myFireEvent(obj,evt) };
	}
} 

function myAttachEventListener(obj, evt, fnc){
	if (!obj.myEvents) obj.myEvents = {};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}

function myFireEvent(obj,evt){
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}

/* -------------------------------------------------------------------- */
/* jQuery Page Method Caller
/* -------------------------------------------------------------------- */

function PageMethod(fn, paramArray, successFn, errorFn)   
{   
  var pagePath = window.location.pathname;   
  //Create list of parameters in the form:   
  //{"paramName1":"paramValue1","paramName2":"paramValue2"}   
  var paramList = '';   
  if (paramArray.length > 0)   
  {   
    for (var i=0; i<paramArray.length; i+=2)   
    {   
      if (paramList.length > 0) paramList += ',';   
      paramList += '"' + paramArray[i] + '":"' + paramArray[i+1] + '"';   
    }   
  }   
  paramList = '{' + paramList + '}';  
   
  //Call the page method   
  $.ajax({   
      type: "POST",   
      url: pagePath + "/" + fn,   
      contentType: "application/json; charset=utf-8",   
      data: paramList,   
      dataType: "json",   
      success: successFn,   
      error: errorFn   
  })   
;} 

/* -------------------------------------------------------------------- */
/* Autoscroll
/* -------------------------------------------------------------------- */

function AutoScroll_Save()
{
    var scrollX, scrollY;

    if (document.all)
    {
        if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
        else
            scrollX = document.documentElement.scrollLeft;

        if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
        else
            scrollY = document.documentElement.scrollTop;
    }   
    else
    {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }

    document.forms[0].xScrollPosition.value = scrollX;
    document.forms[0].yScrollPosition.value = scrollY;
}

function AutoScroll_Scroll()
{
    var x = document.forms[0].xScrollPosition.value;
    var y = document.forms[0].yScrollPosition.value;
    
    window.scrollTo(x, y);
}

//attachEventListener(window, "scroll", AutoScroll_Save, false);
//attachEventListener(window, "keypress", AutoScroll_Save, false);
//attachEventListener(window, "click", AutoScroll_Save, false);


  /* Bookmarking */
 $(function() {
  // add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("div.bookmark a").attr("rel") != ""){
			$("div.bookmark a").attr("rel","sidebar");
		}
	}

	$("div.bookmark a").click(function(event){
		event.preventDefault();
		var url = this.href;
		var title = document.title;
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} 
		else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} 
		else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} 
		else { // for Safari, Konq etc - browsers who do not support bookmarking scripts
			 alert('Unfortunately, this browser does not support the requested action, please bookmark this page manually.');
		}
	});
});
		
$(document).ready(function(){
  if($.fn.superfish) {
    $('ul.sf-menu').superfish({ 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        }); 
  }

$('.galImage').click(function(){
	var imagePath = ($(this).attr('name')+ "&profile=main")
	$('#mainHotImage').attr("src", function() { 
          return "image.axd?img=" + imagePath; 
        });
	});
});

