/*
-------------------------------------------------------------------------------
code language:		js
package name:		files/js/
class name:		Project_pt_overview
class type:		static
version:			4.0
date:			20100927
copyright:		massimo cardascia
url:				www.plustic.de / www.dot-control.com
-------------------------------------------------------------------------------
*/

///*	imports //////////////////////////////////////////////////////////////////

///* class definition /////////////////////////////////////////////////////////
	function Project_pt_overview()
		{
///*		class versionising //////////////////////////////////////////////////
		Project_pt_overview.__s_classVersion = "1.0";					///h	dclib intern class version
		Project_pt_overview.__s_className = "Project_pt_overview";			///h	dclib intern class name
		Project_pt_overview.__s_classType = "class";						///h	dclib intern class type ["class", "subclass"]

///*		class properties ////////////////////////////////////////////////////
		this.__s_filter;
		this.__dat_images;
		this.__dat_images_category_dict;
///*		class system init ///////////////////////////////////////////////////

///*		class constructor ///////////////////////////////////////////////////

///*		public static functions /////////////////////////////////////////////

///*		private static functions ////////////////////////////////////////////

///*		public functions ////////////////////////////////////////////////////

///*		init engine ---------------------------------------------------------
		this.f_initEngine = function()
			{
///*			address change
			$.address.change(function($o_event){Project.__o_page.f_updateStatus()});

///*			scrolling
			$(window).bind("scroll", function(){Project.__o_page.f_updateContent(true);});
			
            $('div#homepage div.content').bind("scroll", function(){Project.__o_page.f_updateContent(true);});

///*			scrolling
			$(window).bind("resize", function(){Project.__o_page.f_updateContent(true);});
			}
        // return true if we are in a category overview
        this.f_in_category = function() {
            // see if the filter key (cat_123 oder client_xyz) starts with "cat"
            return "cat" == this.__s_filter.split('_')[0];
        }
       
        // return true if we are in a client overview
        this.f_in_client = function() {
            return !this.f_in_category();
        }   

///*		change page mode ----------------------------------------------------
		this.f_updateStatus = function($b_init)
			{
///*			properties
			var $s_filter;
			var $jqo_image;
			var $storage_data;
			var $s_display;
			var $a_filter;
			var $i_loop;
			var $i_images = 0;

///*			get current filter
			$s_filter = Project.__a_slug_to_filter_dict[$.address.parameter("filter")];
                        
			if($s_filter == this.__s_filter)
				{
				return;
				}
			this.__s_filter = $s_filter;

            $("#clientIntro").css("display","none");
            if(this.__s_filter.indexOf('client_')>=0){
                var page_uid = this.__s_filter.split("_").pop();
                if(Project.__a_page_texts[page_uid]){
                    $("#clientIntro").css("margin-bottom","10px");
                    $("#clientIntro").css("display","block");
                    $("#clientIntro").html(Project.__a_page_texts[page_uid]);
                } else {
                    $("#clientIntro").css("display","none");
                }
            }

///*			change
            var currentImageDataArray = [];

            if (this.f_in_client()) {
                currentImageDataArray = Project.__a_image_data;
            } else {
                currentImageDataArray = Project.__a_image_categories_data[this.__s_filter];
            }
            for($i_loop = 0; $i_loop < currentImageDataArray.length; $i_loop ++)
				{  
///*				get relevant storage
                if (this.f_in_client()) {
                    $storage_data = this.__dat_images.f_getData({i_index:$i_loop});
                } else {
                    $storage_data = this.__dat_images_category_dict[this.__s_filter].f_getData({i_index:$i_loop});
                }

///*				active
				$storage_data.b_active = ((($storage_data.a_filter.indexOf($s_filter) > -1) || ($s_filter == "all") || ($s_filter == null)) ? true : false);
				$s_display = (($storage_data.b_active == true) ? "block" : "none");

///*				update view
//				$jqo_image = $($storage_data.div_image);
				$storage_data.jqo_image.css("display", $s_display);
				$storage_data.jqo_image.find("img").css("opacity", 0);
				$storage_data.b_visible = false;

///*				update counter
				if($storage_data.b_active == true)
					{
					$i_images ++;
					}
				}

///*			update content
			this.f_updateContent($b_init);

///*			about us
			if (this.__s_filter == 'aboutus') 
				{
				$("#clientIntro").css("opacity", 0);
				$("#clientIntro").animate({opacity:1});
				$("#clientIntro").css("margin-bottom","10px");
				$('#clientIntro').html(Project.__a_page_texts['13']); // magic constants FTW!
				$("#clientIntro").css("display","block");
				}
                
///*			jobs
			if (this.__s_filter == 'jobs') 
				{
				$("#clientIntro").css("opacity", 0);
				$("#clientIntro").animate({opacity:1});
				$("#clientIntro").css("margin-bottom","10px");
				$('#clientIntro').html(Project.__a_page_texts['57']); // magic constants FTW!
				$("#clientIntro").css("display","block");
				}
			}

///*		change page mode ----------------------------------------------------
		this.f_loadImage_complete = function($div_image)
			{
///*			properties
			var $storage_data;		///h	stores data
			
///*			get relevant storage
            if (this.f_in_client()) {
                $storage_data = this.__dat_images.f_getData({div_image:$div_image});
            } else {
                $storage_data = this.__dat_images_category_dict[this.__s_filter].f_getData({div_image:$div_image});
            }
			$storage_data.b_load_complete = true;

///*			update content
			this.f_updateContent();
			}

///*		change page mode ----------------------------------------------------
		this.f_updateContent = function($b_init)
			{
///*			properties
			var $i_pause;			///h	stores pause
			var $storage_data;
			var $i_loop;


///*			change
			$i_pause = (($b_init == true) ? 350 : 50);
            
            var currentImageDataArray = [];
            if (this.f_in_client()) {
                $("#clientImages").css('display', '');
                $("#categoryImages").css('display', 'none');
                currentImageDataArray = Project.__a_image_data;
            } else {
                $("#clientImages").css('display', 'none');
                $("#categoryImages").css('display', '');
                // hide all gallery containers...
                $("#categoryImages .catContainer").css('display', 'none');
                // except the current one.
                $("#" + this.__s_filter).css('display', '');
                currentImageDataArray = Project.__a_image_categories_data[this.__s_filter];
            }
            for($i_loop = 0; $i_loop < currentImageDataArray.length; $i_loop ++)
				{
///*				get relevant storage
                if (this.f_in_client()) {
                    $storage_data = this.__dat_images.f_getData({i_index:$i_loop});
                } else {
                    $storage_data = this.__dat_images_category_dict[this.__s_filter].f_getData({i_index:$i_loop});
                }

///*				load image
				if($storage_data.b_active == true)
					{
///*					check if image on screen
                                        //if(Project.__o_base==""){
                                            $storage_data.b_on_screen = ((($storage_data.jqo_image.viewportOffset().top > $(window).height()) || ($storage_data.jqo_image.viewportOffset().top < -175)) ? false : true);
                                        //}else{
                                        //    $storage_data.b_on_screen = true;
                                        //}
///*					load
					if($storage_data.b_on_screen == true)
						{
						if($storage_data.b_load_start == false)
							{
///*							add image tag
							$storage_data.div_image = $storage_data.jqo_image.find("img")[0];
							$storage_data.jqo_image.find("img").load(function(){Project.__o_page.f_loadImage_complete(this);});
							$storage_data.jqo_image.find("img").delay($i_pause).attr("src", $storage_data.s_url);

///*							start loading
							$storage_data.b_load_start = true;
							$i_pause += 80;
							}

///*						show
						else if($storage_data.b_load_complete == true)
							{
							if($storage_data.b_visible == false)
								{
								$storage_data.jqo_image.find("img").delay($i_pause).animate({opacity:1});
								$storage_data.jqo_image.css("display", "block");
								$storage_data.b_visible = true;
								$i_pause += 80;
								}
							}
						}
					}
				}
			}

///*		change page mode ----------------------------------------------------
		this.f_initContent = function()
			{
///*			properties
			var $o_data;
			var $i_loop;
			var $a_div;
			var $storage_data;

///*			get relevant divs
			$a_div = $("#clientImages .pt_overview_images_container");

///*			create posts database
            for($i_loop = 0; $i_loop < Project.__a_image_data.length; $i_loop ++)
				{
                $storage_data = this.__dat_images.f_getData({i_index:$i_loop});
                                
                                //
                                //alert($storage_data.s_id +' # '+$storage_data.s_clientID +' # '+$storage_data.s_galID);
///*				update storage
				$storage_data.div_image = $a_div[$i_loop];
				$storage_data.jqo_image = $($a_div[$i_loop]);
				
///*				update link
				$storage_data.jqo_image.find("a").attr("href", "javascript:;");
				$storage_data.jqo_image.bind("click", {s_id:$storage_data.s_id,s_galID:$storage_data.s_galID,s_clientID:$storage_data.s_clientID}, function($o_event) {Project.__o_page.f_showDetails($o_event.data.s_id,$o_event.data.s_galID,$o_event.data.s_clientID);});
				}
            var __dat_images_category_dict = this.__dat_images_category_dict;
            $.each(Project.__a_image_categories_data, function(cat_key, __a_image_category_data) {
    ///*			get relevant divs
                $a_div = $("#categoryImages #" + cat_key + " .pt_overview_images_container");
                for($i_loop = 0; $i_loop < Project.__a_image_categories_data[cat_key].length; $i_loop ++)
                    {
                    $storage_data = __dat_images_category_dict[cat_key].f_getData({i_index:$i_loop});
                                    
                                    //
                                    //alert($storage_data.s_id +' # '+$storage_data.s_clientID +' # '+$storage_data.s_galID);
    ///*				update storage
                    $storage_data.div_image = $a_div[$i_loop];
                    $storage_data.jqo_image = $($a_div[$i_loop]);
                    
    ///*				update link
                    $storage_data.jqo_image.find("a").attr("href", "javascript:;");
                    $storage_data.jqo_image.bind("click", {s_id:$storage_data.s_id,s_galID:$storage_data.s_galID,s_clientID:$storage_data.s_clientID}, function($o_event) {Project.__o_page.f_showDetails($o_event.data.s_id,$o_event.data.s_galID,$o_event.data.s_clientID);});
                    }
            });
            this.__dat_images_category_dict = __dat_images_category_dict;
///*			update status
			this.f_updateStatus(true);
			}
			
///*		change page mode ----------------------------------------------------
		this.f_showDetails = function($s_id,$s_galID,$s_clientID)
			{
///*			properties
			var $s_url;

///*			define url
			$s_url = (Project.__o_base+"gallery/" + ($s_clientID.split('_').pop()) + "/" + ($s_galID.split('_').pop()) + "/" + ($s_id.split('_').pop()) + "/"+this.__s_filter+"#/?filter=" + Project.__a_filter_to_slug_dict[this.__s_filter]);
			window.location = $s_url;
			}

///*		change page mode ----------------------------------------------------
		this.f_initData = function()
			{
///*			properties
			var $o_data;
			var $i_loop;
			var $storage_data;
			
///*			data
			this.__s_filter = "init";

///*			create posts database
			this.__dat_images = new DCJS_dataStorage("s_id");
			for($i_loop = 0; $i_loop < Project.__a_image_data.length; $i_loop ++)
				{
///*				get data
				$o_data                         = Project.__a_image_data[$i_loop];
				$storage_data                   = this.__dat_images.f_addData({s_id:$o_data[1]});
				$storage_data.i_index           = $i_loop;
				$storage_data.s_url             = String($o_data[0]);
                                $storage_data.s_galID           = String($o_data[5]);
                                $storage_data.s_clientID        = String($o_data[6]);
                                $storage_data.s_base            = String(Project.__o_base);
				$storage_data.a_filter          = String($o_data[2]).split(",");
				$storage_data.b_load_start      = false;
				$storage_data.b_load_complete   = false;
				$storage_data.b_visible         = false;
				}
            var __dat_images_category_dict = {};
            $.each(Project.__a_image_categories_data, function(cat_key, __a_image_category_data) {
                var __dat_images_category = new DCJS_dataStorage("s_id");
                for($i_loop = 0; $i_loop < __a_image_category_data.length; $i_loop ++)
                    {
    ///*				get data
                    $o_data                         = __a_image_category_data[$i_loop];
                    $storage_data                   = __dat_images_category.f_addData({s_id:$o_data[1]});
                    $storage_data.i_index           = $i_loop;
                    $storage_data.s_url             = String($o_data[0]);
                                    $storage_data.s_galID           = String($o_data[5]);
                                    $storage_data.s_clientID        = String($o_data[6]);
                                    $storage_data.s_base            = String(Project.__o_base);
                    $storage_data.a_filter          = String($o_data[2]).split(",");
                    $storage_data.b_load_start      = false;
                    $storage_data.b_load_complete   = false;
                    $storage_data.b_visible         = false;
                    }
                __dat_images_category_dict[cat_key] = __dat_images_category;
            });
            this.__dat_images_category_dict = __dat_images_category_dict;
			}

///*		change page mode ----------------------------------------------------
		this.f_init = function()
			{
///*			init data
			this.f_initData();

///*			init content
			this.f_initContent();

///*			init engine
			this.f_initEngine();
			}

///*		private functions ///////////////////////////////////////////////////
		}

///*	init system for static functions
var $o_class = new Project_pt_overview();

