
function getWindowDimensions() {
if (self.innerHeight) // all except Explorer
{
	windowWidth = self.innerWidth;
	windowHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
}

if(document.body)
{
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		pageWidth = document.body.offsetWidth;
		pageHeight = document.body.offsetHeight;
	}
}
else
{
	pageWidth = windowWidth;
	pageHeight = windowHeight;
}

}

function recalculate_header(imageobj) {
      getWindowDimensions();
      img="1500";
      if(windowWidth<1500)img="1000";
      if(windowWidth<1000)img="800";
      if(windowWidth<800)img="560";
      imageobj.src = "/nop/.cache/crealogo.jpg"+img+".jpg";
      }


function login(){
	$.ajax({ url: '/login.php',
	       type: 'POST',
	       cache: false,
	       data: 'u='+$("input[name=user]").attr("value")+"&p="+$("input[name=password]").attr("value"),
	       success: function(data){ 
	       		if ( data == "OK" ) { 
				location.reload();
				alert('Login sucssess');
			} else {
			alert('Login Failure'); 
			}
			}
	       });
}
function logout(){
	$.ajax({ url: '/login.php',
	       type: 'POST',
	       cache: false,
	       data: 'u=logout&p=',
	       success: function(data){ 
	       			if ( data == "OK" ) { 
				location.reload();
	       			}
			}
	       });
}
function getAjaxFile(request,code,count){
	$.ajax({ url: '/basket.php', 
		type: 'GET',
	       	cache: false,
		data: 'a='+request+'&l='+code+":"+count+"&view="+view,
		success: function(data){$("#ShoppingBasket").html(data);
			if ( request == "cc" ) { location.reload(); }
			if ( request == "a" ) {
                             $('#basket-'+code).animate({opacity: .01},100, function() {
                             $('#basket-'+code).html('<a href="/checkout.php">In winkelmandje</a>');
                                $('#basket-'+code).animate({opacity: 1},300, function() {
                                        });
                                });
                        }
                        if ( request == "d" ) {
                             $('#basket-'+code).html("");
                        }

			}
	});
}

function updateArticle(code,count){
	count=parseFloat(count);
	if(Math.round(count)!=count){alert("decimalen worden genegeerd");}
	if((count<1)||(isNaN(count))){count=1};
	return getAjaxFile('u',code,count);
}

function addArticle(code,count){
	count=parseFloat(count);
	if(Math.round(count)!=count){alert("decimalen worden genegeerd");}
	if((count<1)||(isNaN(count))){count=1};
	getAjaxFile('a',code,count);
	$("div.scrollArea").scrollTop(500);
}

function deleteArticle(code){
        $('#crea-'+code).animate({opacity: .10},250, function() {
                return getAjaxFile('d',code,'');
                });
}

function flushArticle(){
	return getAjaxFile('f','','');
}

function Toggleaangetekend(){
	return getAjaxFile('p','','');
}

function CreateObject() {
         try {
           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
              try {
                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                   } catch (e) {
              xmlhttp = false;
                }
       }
         if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                try {
                        xmlhttp = new XMLHttpRequest();
                } catch (e) {
                        xmlhttp=false;

        }
        }
        if (!xmlhttp && window.createRequest) {
                try {
                        xmlhttp = window.createRequest();
                } catch (e) {
                        xmlhttp=false;
                }
        }

       return xmlhttp;
}


function enlarge() {	
		picture=$('#vergroten').attr('alt');
		if ( size == "small" ) {
		$('.articledetail').slideUp('800');
		$('#preview').attr('src','/pic/large/'+picture);
		$('#preview').animate({width: 'toggle', height: 'toggle'},50);
		$('#preview').animate({width:"500"},{ queue:false, duration:500} )
		.animate({height:"500"},500);
		size="notsmall";
		} else {	
		$('.articledetail').slideDown('fast');
		$('#preview').animate({width: 'toggle', height: 'toggle'},300);
		$('#preview').attr('src','/pic/'+picture);
		$('#preview').show();
		size="small";
		}
}

function randomized (max) {return Math.floor(Math.random()*max);}


var windowWidth;
var windowHeight;
var pageWidth;
var pageHeight;
var xmlHttp;
function initFn () {
        $('#ShoppingBasket').animate({opacity: .01},300, function() {
		color=$('#ShoppingBasket').css("background-color");
		background_color=$('#ShoppingBasket').css("color");
		$('#ShoppingBasket').css({"background-color":background_color,"color":color});

                $('#ShoppingBasket').animate({opacity: 1},700, function() {
        		$('#ShoppingBasket').animate({opacity: .10},250, function() {
			$('#ShoppingBasket').css({"background-color":color,"color":background_color});
        			$('#ShoppingBasket').animate({opacity: 1},500, function() {
                        		});
                        	});
                        });
                });
}

// Init Jquerys
var timerID = null;
var size="small";
var itype="png";
if ( noalpha == true ) { itype="jpg"; } 

$(".scrollArea").scrollTop(10);
$('#vergroten').click(function(){ enlarge(); });
$('#preview').click(function(){ enlarge(); });
$('#thumbnail').click(function(){ enlarge(); });

getWindowDimensions();
leftcolum=213; s=windowWidth;
if(windowWidth>1400)s=1400;
if(windowWidth<701)s=701;
column=parseInt((s-leftcolum)/156);
c=(column*156)+30; w=parseInt(c+leftcolum);
//$(document).ready(function(){
      $("#contentwrapper").css("width", w+"px" );
      $("#contentcolumn").css("width", c+"px" );
	if (w>800) { 
      	$("#logo1").css("margin-left", parseInt((w-800)/2)+"px" );
	w=800;
	}
      $("#logo1").css("width", w+"px" );
//$(document).ready(function(){
//	$("#topsection").css("height",$("#logo1").attr("height"));
	if (( view == '' ) && ( rowwidth != column )) { getAjaxFile('cc',column,'');}
	//if ( view == '' ) { getAjaxFile('cc',column,'');}
//})

