Contactus = new Object();
Product = new Object();
Product.selectedID;
Product.previousID;

Gallery = new Object();
Gallery.selectedID;
Gallery.previousID;

Content.selectedID;
Content.previousID;

//**********************************************************************************//
Product.getProductDetail = function(product_id, clicked){

   var divObj = document.getElementById("productDetail");
   var imgSrc = '<div align="center"><img src="/images/loading.gif" border="0" align="center"></div>';
   divObj.innerHTML = imgSrc;

   var url = "/index.php?_spAction=productDetail" + "&product_id=" + product_id + "&showHTML=0" ;

   $('#productDetail').load(url, function(){
      if (clicked == 1){
         if (Product.previousID != "" && Product.previousID != undefined ){
            document.getElementById(Product.previousID).style.color = "#7F7F7F";
         }
         document.getElementById(product_id).style.color = "#008AD3";

         Product.previousID = product_id;
         Product.selectedID = product_id;

         $('.centered img').load(function(){
            $(".centered").cp_center();
         });

      }
      
   });
}

//**********************************************************************************//
Gallery.getGalleryDetail = function(gallery_id, clicked){

   var divObj = document.getElementById("galleryDetail");
   var imgSrc = '<div align="center"><img src="images/loading.gif" border="0" align="center"></div>';
   divObj.innerHTML = imgSrc;

   var url = "/index.php?_spAction=galleryDetail" + "&gallery_id=" + gallery_id + "&showHTML=0" ;

   $('#galleryDetail').load(url, function(){

      if (clicked == 1){
         if (Gallery.previousID != "" && Gallery.previousID != undefined ){
            document.getElementById(Gallery.previousID).style.color = "#7F7F7F";
         }
         document.getElementById(gallery_id).style.color = "#008AD3";
      }

      Gallery.previousID = gallery_id;
      Gallery.selectedID = gallery_id;

      $('.centered img').load(function(){
            $(".centered").cp_center();
      });
      
   });
}

//**********************************************************************************//
Functions.changeProductNormalImage = function(imageName, mediaID){
  imgSrc   = "/media/product/normal/" + imageName;
  linkTemp = "/index.php?_room=media&_spAction=zoomImage&media_id=" + mediaID;
  linkSrc  = "javascript:UtilWindow.openWindow(linkTemp,'1010','800')";
  document.getElementById("productImage").src = imgSrc;
  document.getElementById("largeImage").href  = linkSrc;
}

//**********************************************************************************//
Functions.changeGalleryNormalImage = function(imageName, mediaID){
  imgSrc   = "/media/gallery/normal/" + imageName;
  linkTemp = "/index.php?_room=media&_spAction=zoomImage&media_id=" + mediaID;
  linkSrc  = "javascript:UtilWindow.openWindow(linkTemp,'1010','800')";
  document.getElementById("galleryImage").src = imgSrc;
  document.getElementById("largeImage").href  = linkSrc;
}

//**********************************************************************************//
Functions.popUp = function(windowURL,windowName,windowWidth,windowHeight) {

   window.name = 'parentWnd';
   newWindow = window.open(windowURL,windowName,'width='+windowWidth+',height='+windowHeight+',toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');
}

//**********************************************************************************//
Content.getContentDetail = function( content_id, clicked){

   var divObj = document.getElementById("contentDetail");
   var imgSrc = '<div align="center"><img src="images/loading.gif" border="0" align="center"></div>';
   divObj.innerHTML = imgSrc;

   var url = "/index.php?_spAction=contentDetail" + "& content_id=" +  content_id + "&showHTML=0" ;

   var formContent = 'xyz=1';


   XMLHTTP.xmlHttpObj = XMLHTTP.getXMLHTTPObject(function () {Content.getContentDetailHandler( content_id, clicked);});
   XMLHTTP.xmlHttpObj.open("POST", url, true);
   XMLHTTP.xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   XMLHTTP.xmlHttpObj.send(formContent);
}

//**********************************************************************************//
Content.getContentDetailHandler = function( content_id, clicked){

   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") {
      var responseText = XMLHTTP.xmlHttpObj.responseText;

      if (clicked == 1){

         if (Content.previousID != "" && Content.previousID != undefined ){
            document.getElementById(Content.previousID).style.color = "#7F7F7F";
         }
         document.getElementById( content_id).style.color = "#008AD3";
      }

      var divObj = document.getElementById("contentDetail");
      divObj.innerHTML = responseText;

      Content.previousID =  content_id;
      Content.selectedID =  content_id;
   }

}

//**********************************************************************************//
Contactus.getContactusDetail = function(content_id, clicked){

   var divObj = document.getElementById("contactusDetail");
   var imgSrc = '<div align="center"><img src="/images/loading.gif" border="0" align="center"></div>';
   divObj.innerHTML = imgSrc;

   var url = "/index.php?_spAction=contentDetail" + "&content_id=" + content_id + "&showHTML=0" ;

   var formContactus = 'xyz=1';


   XMLHTTP.xmlHttpObj = XMLHTTP.getXMLHTTPObject(function () {Contactus.getContactusDetailHandler(content_id, clicked);});
   XMLHTTP.xmlHttpObj.open("POST", url, true);
   XMLHTTP.xmlHttpObj.setRequestHeader("Contactus-Type","application/x-www-form-urlencoded; charset=UTF-8");
   XMLHTTP.xmlHttpObj.send(formContactus);
}

//**********************************************************************************//
Contactus.getContactusDetailHandler = function(content_id, clicked){

   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") {
      var responseText = XMLHTTP.xmlHttpObj.responseText;

      if (clicked == 1){

         if (Contactus.previousID != "" && Contactus.previousID != undefined ){
            document.getElementById(Contactus.previousID).style.color = "#7F7F7F";
         }
         document.getElementById(content_id).style.color = "#008AD3";
      }

      var divObj = document.getElementById("contactusDetail");
      divObj.innerHTML = responseText;

      Contactus.previousID = content_id;
      Contactus.selectedID = content_id;
   }

}
//**********************************************************************************//


$(function(){
   hash = document.location.hash;
});

$(function() {
   /*
   $(".centered").livequery(function(){
      $(window).load(function(){
         $(".centered").cp_center();
      });
   });
   */
});


//------------------------------------------------//
var RelatedPictures = {

      changePicture: function() {

         $('.relatedPicture a').click(function(e) {
            e.preventDefault();
            var imgObj      = $('img#productImage');
            var linkObj     = $('a#largeImage');
            var normalImage = $(this).attr('href');
            var largeImage  = $(this).children().attr('largeFile');
            var caption     = $(this).children().attr('caption');

            $(imgObj).hide();
            $('#productImage').addClass('loading');
            $(imgObj).load(function () {
                $(this).hide();
                $('#productImage').removeClass('loading');
                $(this).fadeIn();
            }).error(function () {
            
            }).attr('src', normalImage);
            
            $(linkObj).attr('href', largeImage);
            
            if(caption != ""){
                $('#imageDescription').html(caption);
            }
            
         });

         $('a#largeImage').click(function(e){
                 e.preventDefault();
                 largeImgUrl = $(this).attr('href');
                 
                 var imgObj = new Image ();
                 imgObj.src = largeImgUrl;
                 
                 $(imgObj).load(function () {
                    var w = imgObj.width  + 20; 
                    var h = imgObj.height + 20; 
                    var options = {
                        url: largeImgUrl,
                        width: w,
                        height: h
                    };
                    
                    $(this).cp_openWindow(options)
                 });
         });
      }
}

//------------------------------------------------//
var Project = {
   setDetail: function(sub_category_id){
      var url = "/index.php?_spAction=projectDetail" + "&sub_category_id=" + sub_category_id + "&showHTML=0" ;
      $.get(url, function(data){
         $('#projectDetail').html(data);
      });
   }
}