// JavaScript Document

function printManager(pURL){

	var iHeight = 600 ;
	var iWidth = 800 ;
	window.open(pURL, 'BellRoss', 'width=' + iWidth + ', height=' + iHeight + ', toolbar=no, menubar=no, location=no, resizable=no, scrollbars=no, status=no');
	

}

function gobackOneStep() {
	//alert('goBackOneStyep');
	history.go(-1);	
}

function updatePayment(pURL, pLang, pCountry) {
	
	var sURL = sHttpRoot + "bank_request/" ;
	window.location.replace(sURL);

}

function launchCatalogue(){
	
	var page = 'http://www.bellross.com/catalog/catalog_2010/' ;
	var name = 'BellRoss' ;
	var option = 'fullscreen=yes' ;
	window.open(page,name,option);

}

function launchCatalogueNews(){
	
	var page = 'http://www.bellross.com/catalog/catalog_2011/' ;
	var name = 'BellRoss' ;
	var option = 'fullscreen=yes' ;
	window.open(page,name,option);

}

function launchGallery(){
	
	var page = sHttpRoot + 'gallery/' ;
	var name = 'BellRoss' ;
	var option = 'fullscreen=yes' ;
	window.open(page,name,option);

}

function ExternalAPICall(type, params){

	switch (type){
	
		default :
		case 'gmap' :
		
			$.ajax({
				url: 'http://maps.googleapis.com/maps/api/geocode/json',
				data: {
					sensor: false,
					address: params
				},
				dataType : 'jsonp',
				callback: function (data) {
					var myObj = eval( "(" + data + ")" );
					ExternalAPISendResponse(myObj) ;
				}
			});	
			
		break;
				
	}

}

function ExternalAPISendResponse(response_text){
	
	document.getElementById("br_website").appelAS3(response_text);
	
}

function resizeInit()
{
	window.onorientationchange();
	window.onresize() ;
	$("#footer > div.social").click(function(){openSharings();});

}

function openSharings()
{
	var content = '<div><div style="padding:30px;"><ul class="social_items">' ;
	content += $("#footer > UL.social_items").html();
	content += "</ul></div></div>" ;
	updateOverlayContent(content);
	$("#overlay_close").css("display", "none");
	$("#overlay_background").click(function(){hideOverlay();});
}

window.onresize = function(){
	var sizes = getWindowBounds();
	if(document.getElementById('overlay_background')){
		var background = document.getElementById('overlay_background') ;
		background.style.width = sizes.width + 'px' ;
		background.style.height = sizes.height + 'px' ;
	}
	redim();
	
	
}

window.onorientationchange = function ()
{
    viewport = document.querySelector("meta[name=viewport]");
    if(viewport)
    {
		if(orientation == 0 || orientation == 180)
        {
			var iWidthDevice = window.innerWidth ;
			var iRatio = iWidthDevice / 1024 ;
			//alert(iWidthDevice);
            viewport = document.querySelector("meta[name=viewport]");
            viewport.setAttribute('content', 'width=device-width; initial-scale=' + iRatio + '; maximum-scale=' + iRatio + '; user-scalable=0;');
            $("#switch_overlay").click(function (){
                $("#switch_overlay").html('') ;
                $("#switch_overlay").css("display", "none") ;
            });
            $("#switch_overlay").html('<div id="switch_overlay_background"></div><img id="switch_overlay_content" src="media/switch_to_landscape.gif" width="500" height="391" />') ;
            $("#switch_overlay").css("display", "block") ;
            $("#switch_overlay").css("width", "100%") ;
            $("#switch_overlay").css("height", "100%") ;
            $("#switch_overlay_background").css("background-color", "#000000") ;
            $("#switch_overlay_background").css("width", getWindowWidth()) ;
            $("#switch_overlay_background").css("height", getWindowHeight()) ;            
        } 
        else 
        {
            viewport = document.querySelector("meta[name=viewport]");
            viewport.setAttribute('content', 'width=1024; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;');
            $("#switch_overlay").html('') ;
            $("#switch_overlay").css("display", "none") ;

        }
    }
}

if (window.attachEvent) window.attachEvent("onload", resizeInit)
else window.addEventListener('load', resizeInit, false);

