﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}
 function toCallPopupDsbl(e){
 if(e.keyCode==27 && popupStatus==1){
  disablePopup();
 }
}
//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	scroll(0,0);
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/7-popupHeight/7,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight
	});

}
//function showtext(thetext){
//     if (!document.getElementById)
//        return
//    textcontainerobj=document.getElementById("")
//    browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
//    instantset(baseopacity)
//    document.getElementById("tabledescription").innerHTML=thetext
//    highlighting=setInterval("gradualfade(textcontainerobj)",50)
//}
//
//function hidetext(){
//cleartimer()
//instantset(baseopacity)
//}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the button event!
	$(".popup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});





	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});



function showPopupForHomeApps(id){
   	document.getElementById('popupBody').innerHTML="<img ";
	centerPopup();
	loadPopup();
	$.ajax({
		type: "GET",
		url: "product/show/"+id,
		dataType: "html",
		success: function(data){
       			document.getElementById('popupBody').innerHTML=data;
                        setTimeout("doNext()", 5000);
                         $('.popupSlideshow')
                            .after('<div id="popupSlideNav" align="center">')
                            .cycle({
                                    fx:     'fadeZoom',
                                    speed:  600,
                                    pager:  '#popupSlideNav'
                            });
                                    }
                         });
}
function showBannerPopup(id){
    // document.getElementById(t.id).style.color= "green";

    document.getElementById('popupBody').innerHTML="<img ";
	centerPopup();
	loadPopup();
	$.ajax({
		type: "GET",
		url: "../../product/show/"+id,
		dataType: "html",
		success: function(data){
       			document.getElementById('popupBody').innerHTML=data;
                        setTimeout("doNext()", 1000);
                         $('.popupSlideshow')
                            .after('<div id="popupSlideNav" align="center">')
                            .cycle({
                                    fx:     'fadeZoom',
                                    speed:  600,
                                    pager:  '#popupSlideNav'
                            });
                                    }
                             });

}

function doNext(){
     for(i=1;i<5;i++){
         var imgObj=document.getElementById('screen'+i);
         imgObj.style.width=imgObj.clientWidth;
         imgObj.style.height=imgObj.clientHeight;
    }
}
function waitFor(imgId){

    var imgObj=document.getElementById(imgId);
    if(!imgObj.complete){
        imgWait=setTimeout('waitFor("'+imgId+'")', 500);
    }
    else{
        // Code to execute on completion of download
        imgObj.style.width=imgObj.clientWidth;
        imgObj.style.height=imgObj.clientHeight;
   }
}

function showPopup(id){
       // document.getElementById(t.id).style.color= "green";
   	document.getElementById('popupBody').innerHTML="<img ";
        centerPopup();
         loadPopup();
	$.ajax({
		type: "GET",
		url: "../product/show/"+id,
		dataType: "html",
		success: function(data){
       			document.getElementById('popupBody').innerHTML=data;
                        setTimeout("doNext()", 1000);
                        $('.popupSlideshow')
                        .after('<div id="popupSlideNav" align="center">')
                        .cycle({
                                fx:     'fadeZoom',
                                speed:  600,
                                pager:  '#popupSlideNav'
                        });
                                }
                   });
}
//function joltJavaScript(){
// var x=document.getElementById('popupBody').getElementsByTagName('script');
// var h=document.getElementsByTagName('head')[0]; // URL Ref: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23214126.html
// for(var i=0;i<x.length;i++){
//  var s=document.createElement("script");
//  s.type="text/javascript";
//  h.appendChild(s);
//  s.text=x[i].text;
// }
//}
